title: Python: Searching a directory and subdirectories for a certain file type
body: <p>I have a folder that contains a few files of different types (<code>.cpp</code>, <code>.hpp</code>, <code>.ipp</code> ...) and in that folder are multiple sub-folders which also contain these different file types. My question is, is there a single loop that I can make that will search the first main folder and return a list full of all the <code>.cpp</code> files from either folder? So far, I know that:</p>
  <p><code>folder_list = [f for f in os.listdir(os.getcwd()) if os.path.isdir(f)]</code></p>
  <p>will return a list of the sub-folders, and then I can change the working directory and get the files list to append.</p>
  <p>I also know that:</p>
  <pre><code>file_list = [f for f in listdir(os.getcwd()) if isfile(join(os.getcwd(), f))]
  </code></pre>
  <p>will return a list of the files.</p>
  <p>However, I won't know the names of these sub-folders (and therefore the directory) beforehand. Thank you for any help</p>