title: How do I copy an entire directory of files into an existing directory using Python?
body: <p>Run the following code from a directory that contains a directory named <code>bar</code> (containing one or more files) and a directory named <code>baz</code> (also containing one or more files).  Make sure there is not a directory named <code>foo</code>.</p>
  
  <pre><code>import shutil
  shutil.copytree('bar', 'foo')
  shutil.copytree('baz', 'foo')
  </code></pre>
  
  <p>It will fail with:</p>
  
  <pre><code>$ python copytree_test.py 
  Traceback (most recent call last):
    File "copytree_test.py", line 5, in &lt;module&gt;
      shutil.copytree('baz', 'foo')
    File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/shutil.py", line 110, in copytree
    File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/os.py", line 172, in makedirs
  OSError: [Errno 17] File exists: 'foo'
  </code></pre>
  
  <p>I want this to work the same way as if I had typed:</p>
  
  <pre><code>$ mkdir foo
  $ cp bar/* foo/
  $ cp baz/* foo/
  </code></pre>
  
  <p>Do I need to use <code>shutil.copy()</code> to copy each file in <code>baz</code> into <code>foo</code>? (After I've already copied the contents of 'bar' into 'foo' with <code>shutil.copytree()</code>?)  Or is there an easier/better way?</p>