title: How to do a recursive sub-folder search and return files in a list?
body: <p>I am working on a script to recursively go through subfolders in a mainfolder and build a list off a certain file type. I am having an issue with the script. It's currently set as follows:</p>
  <pre><code>for root, subFolder, files in os.walk(PATH):
      for item in files:
          if item.endswith(&quot;.txt&quot;) :
              fileNamePath = str(os.path.join(root,subFolder,item))
  </code></pre>
  <p>the problem is that the <code>subFolder</code> variable is pulling in a list of subfolders rather than the folder that the ITEM file is located. I was thinking of running a for loop for the subfolder before and join the first part of the path but I figured I'd double check to see if anyone has any suggestions before that.</p>