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>In this example you define your file folder before, and an array of destination folders. Python then iterates through the destinations in a <code>for</code> loop. Note the use of <code>os.path.join</code>, which is a safe way of building file paths for cross-platform work.</p>

<pre><code>import shutil
import os


full_file_path =  os.path.join('home', 'orig')
paths = [os.path.join('home', 'destA'), os.path.join('home', 'destB')]
for path in paths:
    shutil.copy(full_file_path, path)
</code></pre>

python