title: Copy specific subdirectories by its name with Python
body: <p>If I have a folder which has multiple subfolders, each has same structure sub1, sub2 and sub3:</p>
  
  <pre><code>├─a
  │  ├─sub1
  │  ├─sub2
  │  └─sub3
  ├─b
  │  ├─sub1
  │  ├─sub2
  │  └─sub3
  └─c
      ├─sub1
      ├─sub2
      └─sub3
  ...
  </code></pre>
  
  <p>I want to copy <code>sub1</code> and <code>sub2</code> if there are image files inside and ignore other subfolders (<code>sub3...</code>) while keeping tree structure of directory. This is expected result:</p>
  
  <pre><code>├─a
  │  ├─sub1
  │  └─sub2
  ├─b
  │  ├─sub1
  │  └─sub2
  └─c
      ├─sub1
      └─sub2
  ...
  </code></pre>
  
  <p>What should I do to get expected result? I have try following code but it only copy <code>sub1</code>, <code>sub2</code> and <code>sub3</code>, I got <code>TypeError: copy() takes no arguments (1 given)</code>. </p>
  
  <p>Thanks to @PrasPJ.</p>
  
  <pre><code>import os
  import os.path
  import shutil
  import fnmatch
  
  src_dir= ['C:/Users/User/Desktop/source/input']      # List of source dirs
  included_subdirs = ['sub1', 'sub2']        # subdir to include from copy
  dst_dir = 'C:/Users/User/Desktop/source/output'     # folder for the destination of the copy
  for root_path in src_dir:
      #print(root_path)
      for root, dirs, files in os.walk(root_path): # recurse walking
          for dir in included_subdirs:
              #print(dir)
              if dir in dirs:
                  source = os.path.join(root,dir)
                  f_dst = source.replace(root_path, dst_dir)
                  print (source, f_dst)
                  for file in os.listdir(source):
                      print(file)
                      if file.endswith(".jpg") or file.endswith(".jpeg"):
                          shutil.copytree(source, f_dst)
  </code></pre>
  
  <p>Reference related:</p>
  
  <p><a href="https://www.daniweb.com/programming/software-development/threads/356380/how-to-copy-folders-directories-using-python" rel="nofollow noreferrer">https://www.daniweb.com/programming/software-development/threads/356380/how-to-copy-folders-directories-using-python</a></p>
  
  <p><a href="https://stackoverflow.com/questions/42487578/python-shutil-copytree-use-ignore-function-to-keep-specific-files-types">Python shutil copytree: use ignore function to keep specific files types</a></p>
  
  <p><a href="https://stackoverflow.com/questions/45333182/how-to-copy-contents-of-a-subdirectory-in-python">How to copy contents of a subdirectory in python</a></p>