title: How to make python read all files in directory for a dictionary?
body: <p>I have a collection of 20 text files in a folder that I am trying to create a dictionary for and output the dictionary to a text file.</p>
  
  <p>I created a code that works for a single file in the directory by inputting a filename.  However it doesn't let me input multiple text files at once, and if I run each one individually they just overwrite each other.  I tried converting the file input to using import os and read from my cwd, but I'm running into errors with variables and I'm just not sure what I'm doing wrong.</p>
  
  <pre><code>fname = input ('Enter File: ')
  hand = open(fname)
  
  di = dict()
  for lin in hand:
      lin = lin.rstrip()
      wds = lin.split()
      for w in wds:
  
  
          di[w] = di.get(w,0) + 1
  
  print(di)
  
  
  largest = -1
  theword = None
  for k,v in di.items() : 
      if v &gt; largest : 
          largest = v
          theword = k
  
  print(theword,largest)
  
  f = open("output.txt", "w")
  f.write(str(di))
  f.close()
  </code></pre>
  
  <p>I tried adding </p>
  
  <pre><code>import os
  for filename in os.listdir(os.getcwd()):
      fname = ('*.txt')
      hand = open(fname)
  </code></pre>
  
  <p>To the top, but I'm erroring out as it's not recognizing what I thought would be a wildcard to assign fname as the file it is reading.</p>