title: Copying and merging directories excluding certain extensions
body: <p>I want to copy multiple directories with identical structure (subdirectories have the same names) but different contents into a third location and merge them. At the same time, i want to ignore certain file extensions and not copy them.</p>
  
  <hr>
  
  <p>I found that the first task alone can be easily handled by <code>copy_tree()</code> function from the <code>distutils.dir_util</code> library. The issue here is that the <code>copy_tree()</code> cannot ignore files; it simply copies everything..</p>
  
  <blockquote>
    <p>distutils.dir_util.copy_tree() - example</p>
  </blockquote>
  
  <pre><code>dirs_to_copy = [r'J:\Data\Folder_A', r'J:\Data\Folder_B']
  destination_dir = r'J:\Data\DestinationFolder'
  for files in dirs_to_copy:
      distutils.dir_util.copy_tree(files, destination_dir)
      # succeeds in merging sub-directories but copies everything.
      # Due to time constrains, this is not an option.
  </code></pre>
  
  <hr>
  
  <p>For the second task (copying with the option of excluding files) there is the <code>copytree()</code> function from the <code>shutil</code> library this time. The problem with that now is that it cannot merge folders since the destination directory must not exist..</p>
  
  <blockquote>
    <p>shutil.copytree() - example</p>
  </blockquote>
  
  <pre><code>dirs_to_copy = [r'J:\Data\Folder_A', r'J:\Data\Folder_B']
  destination_dir = r'J:\Data\DestinationFolder'
  for files in dirs_to_copy:
      shutil.copytree(files, destination_dir, ignore=shutil.ignore_patterns("*.abc"))
      # successfully ignores files with "abc" extensions but fails 
      # at the second iteration since "Destination" folder exists..
  </code></pre>
  
  <p>Is there something that provides the best of both worlds or do i have to code this myself?</p>