title: Need to process all files in a directory, but am only getting one
body: <p>I have a Python script that is successfully processing single files. I am trying to write a <code>for</code> loop to have it get all the files in a directory that the user inputs. However, it is only processing one of the files in the directory.</p>
  <p>The code below is followed by the rest of the script that does the analysis on <code>data</code>. Do I need to somehow close the <code>for</code> loop?</p>
  <pre><code>import os
  
  print &quot;Enter the location of the files: &quot;; directory = raw_input()
  path = r&quot;%s&quot; % directory
  
  for file in os.listdir(path):
      current_file = os.path.join(path, file)
  
      data = open(current_file, &quot;rb&quot;)
  
      # Here's an abridged version of the data analysis
  
      for i in range(0, 10):
          fluff = data.readline()
  
      Input_Parameters = fluff.split(&quot;\t&quot;)
  
      output.write(&quot;%f\t%f\t%f\t%f\t%.3f\t%.1f\t%.2f\t%.2f\t%s\n&quot; % (Voc, Isc, Vmp, Imp, Pmax, 100 * Eff, IscErr, 100 * (1 - (P2 / Pmax)), file))
      data.close()
  </code></pre>