title: Python recursive folder read
body: <p>I have a C++/Obj-C background and I am just discovering Python (been writing it for about an hour).
  I am writing a script to recursively read the contents of text files in a folder structure.</p>
  
  <p>The problem I have is the code I have written will only work for one folder deep. I can see why in the code (see <code>#hardcoded path</code>), I just don't know how I can move forward with Python since my experience with it is only brand new.</p>
  
  <p><strong>Python Code:</strong></p>
  
  <pre><code>import os
  import sys
  
  rootdir = sys.argv[1]
  
  for root, subFolders, files in os.walk(rootdir):
  
      for folder in subFolders:
          outfileName = rootdir + "/" + folder + "/py-outfile.txt" # hardcoded path
          folderOut = open( outfileName, 'w' )
          print "outfileName is " + outfileName
  
          for file in files:
              filePath = rootdir + '/' + file
              f = open( filePath, 'r' )
              toWrite = f.read()
              print "Writing '" + toWrite + "' to" + filePath
              folderOut.write( toWrite )
              f.close()
  
          folderOut.close()
  </code></pre>