title: Reading all files in all directories
body: <p>I have the code working to read in the values of a single text file but am having difficulties reading all files from all directories and putting all of the contents together.</p>
  
  <p>Here is what I have:</p>
  
  <pre><code>filename = '*'
  filesuffix = '*'
  location = os.path.join('Test', filename + "." + filesuffix)
  Document = filename
  thedictionary = {}
  with open(location) as f:
   file_contents = f.read().lower().split(' ') # split line on spaces to make a list
   for position, item in enumerate(file_contents): 
       if item in thedictionary:
        thedictionary[item].append(position)
       else:
        thedictionary[item] = [position]
  wordlist = (thedictionary, Document)
  #print wordlist
  #print thedictionary
  </code></pre>
  
  <p>note that I am trying to stick the wildcard * in for the filename as well as the wildcard for the filesuffix. I get the following error:</p>
  
  <p>"IOError: [Errno 2] No such file or directory: 'Test/<em>.</em>'"</p>
  
  <p>I am not sure if this is even the right way to do it but it seems that if I somehow get the wildcards working - it should work.</p>
  
  <p>I have gotten this example to work:  <a href="https://stackoverflow.com/questions/15580716/python-reading-files-from-directory-file-not-found-in-subdirectory-which-is-t">Python - reading files from directory file not found in subdirectory (which is there)</a></p>
  
  <p>Which is a little different - but don't know how to update it to read all files. I am thinking that in this initial set of code:</p>
  
  <pre><code>previous_dir = os.getcwd()
  os.chdir('testfilefolder')
  #add something here?
  for filename in os.listdir('.'):
  </code></pre>
  
  <p>That I would need to add something where I have an outer for loop but don't quite know what to put in it..</p>
  
  <p>Any thoughts?</p>