0

I have some python code that I use to copy files from one directly to another, however it is a very slow process and is sequential. I would like to find a way to do multithreading, copying more that one by one file, but rather have 10 or 100 processes running doing this. Here is my current core that process one by one file:

import os
import shutil

directory = "All_files"

with open('files.txt','w') as f:
    for filename in os.listdir(directory):
        src = directory+"/"+filename+"/02-Partners.pdf"
        file_exists = os.path.exists(src)
        if file_exists == True:
            dst="part/"+filename+"_"+"02-Partners.pdf"
            shutil.copyfile(src,dst)
            f.write('%s \n' % (filename))

Any assistance in getting multiple files copying at the same time will be appreciated.

1
  • try the threading library it is part of python's standard library Commented Jun 14, 2022 at 13:39

1 Answer 1

1

Take a look at python's threading basic package and see if it fits you.

https://docs.python.org/3/library/threading.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.