title: Python: read multiple source txt files, copy by criteria into 1 output file
body: <p>My objective is to read multiple txt source files in a folder (small size), then copy lines selected by criteria into one output txt file.
  I can do this with 1 source file, but I have no output (empty) when I try to read multiple files and do the same.</p>
  
  <p>With my SO research I wrote following code (no output):</p>
  
  <pre><code>import glob
  # import re  --- taken out as 'overkill'
  
  path = 'C:/Doc/version 1/Input*.txt'   # read source files in this folder with this name format
  list_of_files=glob.glob(path)   
  
  criteria = ['AB', 'CD', 'EF']   # select lines that start with criteria
  
  #list_of_files = glob.glob('./Input*.txt')
  
  with open("P_out.txt", "a") as f_out:
      for fileName in list_of_files:
          data_list = open( fileName, "r" ).readlines()
      for line in data_list:
          for letter in criteria:
              if line.startswith(letter): 
                  f_out.write('{}\n'.format(line))
  </code></pre>
  
  <p>Thank you for your help.</p>
  
  <p>@abe and @ppperry: I'd like to particularly thank you for your earlier input.</p>