Python Forum
How do I copy files faster with python?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I copy files faster with python?
#1
Hey guys I know that this issue has already been adressed in a previous threads (https://stackoverflow.com/questions/2207...files-fast ), but I didn't manage to apply the solution to my own code (sorry, I'm rather new to Python) so I thought I´d ask again. Here´s my problem:

I created a simple app that compares the content of two folders and copies the new files of one folder into the other (I used the filecmp-statement for the comparison, so far so good). As for the copy-part, I used the shutil.copy-module.

As it has already been discussed in previous threads, the shutil.copy-module is way slower than the native command for copying files in windows (e.g. it took my code about 94 seconds to copy 800MB, while it took the ordinary copy and paste method in windows about 30 seconds for the same files).

I would be really grateful if somebody could have a look at my code and tell me how to implement a faster copying method (e.g. subprocess.call or native command) in my code. Thanks in advance for your help!

import shutil   
import filecmp
import os

comparison = filecmp.dircmp(r"C:\Users\j2the\Documents\Test2", r"C:\Users\j2the\Documents\Test1")

def analyze():
    for e in comparison.right_only:
        print(e)
        os.chdir(r"C:\Users\j2the\Documents\Test1")
        shutil.copy(e, r"C:\Users\j2the\Documents\Test2")

analyze()
Reply


Messages In This Thread
How do I copy files faster with python? - by steckinreinhart619 - Jul-14-2019, 07:52 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why is the copy method name in python list copy and not `__copy__`? YouHoGeon 2 334 Apr-04-2024, 01:18 AM
Last Post: YouHoGeon
  Copy Paste excel files based on the first letters of the file name Viento 2 512 Feb-07-2024, 12:24 PM
Last Post: Viento
  Create new folders and copy files cocobolli 3 1,567 Mar-22-2023, 10:23 AM
Last Post: Gribouillis
  Copy only hidden files and folders with rsync Cannondale 2 1,081 Mar-04-2023, 02:48 PM
Last Post: Cannondale
  Compare filename with folder name and copy matching files into a particular folder shantanu97 2 4,600 Dec-18-2021, 09:32 PM
Last Post: Larz60+
  Copy documents to Teams using python SallySmith 0 2,428 Mar-23-2021, 04:27 AM
Last Post: SallySmith
  Copy files from subfolders into same name of subfolders at other directory rathoreanil 1 2,416 Oct-12-2020, 01:30 AM
Last Post: Larz60+
  need to define date range of files to copy over OTH 4 3,202 Aug-07-2020, 12:29 PM
Last Post: buran
  Search for files and copy them to different location jayser247 4 2,546 Apr-25-2020, 12:50 AM
Last Post: jayser247
  To Copy text values to Excel using Python ksasi2k3 16 16,113 Dec-26-2019, 11:59 AM
Last Post: ashutoshdeodhar

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020