adding multiple directories as destination when copying files in python
<p>I want to copy an entire directory or just files from a directory to two or more directories at the same time. I'm struggling with the syntax to add more directories for the destination, so the copy is done at the same time (as I'll run a cron job). </p>

<p>Everything works fine if I have one single directory, however I need to add two or more.</p>

<p>The last line of code is:</p>

<pre><code>shutil.copy(full_file_name, r'S:\\A')
</code></pre>

<p>I want to add more destination folders after S:\</p>

<p>(this is for Win machines)</p>

<p>Thanks for help!</p>

<p>If you want to copy the files at the same time, you should use <a href="https://docs.python.org/3/library/multiprocessing.html" rel="nofollow">multiprocessing</a>.
In this sample, we have two files file1.txt and file2.txt and we will copy them to c:\temp\0 and c:\temp\1. </p>

<pre><code>import multiprocessing
import shutil

def main():
    orgs = ['c:\\temp\\file1.txt']
    dests = ['c:\\temp\\0\\', 'c:\\temp\\1\\'] 
    num_cores = multiprocessing.cpu_count()
    p = multiprocessing.Pool(num_cores)
    operations =  [(x,y) for x in orgs for y in dests]
    p.starmap(shutil.copy, operations)
    p.close()
    p.join()

if __name__ == "__main__":
    main()
</code></pre>

python