title: How to recursively copy all files with a certain extension in a directory using Python?
body: <p>I'm trying to write a Python function that copies all .bmp files from a directory and its sub-directories into a specified destination directory.</p>
  
  <p>I've tried using os.walk but it only reaches into the first sub-directory and then stops. Here's what I have so far:</p>
  
  <pre><code>def copy(src, dest):
  
      for root, dirs, files in os.walk(src):
          for file in files:
              if file[-4:].lower() == '.bmp':
                  shutil.copy(os.path.join(root, file), os.path.join(dest, file))
  </code></pre>
  
  <p>What do I need to change so it copies every .bmp file from every sub-directory?</p>
  
  <p>EDIT: This code actually does work, there were just fewer bitmap files in the source directory than anticipated. However, for the program I am writing, I prefer the method using glob shown below.</p>