title: Searching in files and folder is extremely slow in Python
body: <p>i'll try to explain what i want to achieve with my code:</p>
  
  <ol>
  <li>i open a csv file </li>
  <li>i pick up every element of the first row and search for this string in every file in every subdirectory starting from rootdir.</li>
  </ol>
  
  <p>with the design showed below, it is extremely slow even with 2 directories and one file in each directory.
  It takes approximately 1 second for each entry on the main file. i've got 400000 records on that file...</p>
  
  <pre><code>import csv
  import os
  
  rootdir = 'C:\Users\ST\Desktop\Sample'
  f = open('C:\Users\ST\Desktop\inputIds.csv')
  f.readline()
  snipscsv_f=csv.reader(f, delimiter='    ')
  for row in snipscsv_f:
      print 'processing another ID'
      for subdir, dir, files in os.walk(rootdir):
          print 'processing another folder'
          for file in files:
              print 'processing another file'
              if 'csv' in file: #i want only csv files to be processed
                  ft = open(os.path.join(subdir, file))
                  for ftrow in ft:
                      if row[0] in ftrow:
                          print row[0]
                  ft.close()
  </code></pre>