title: How to process multiple files based on their names?
body: <p>With below code Im collecting files from multiple directories. I check their dates, check if they are present in list <code>missing_dates</code> and I check if that specific date is present in every directory. After that, I process those files with the same date to 1 file.</p>
  <p>Short said: 3 files of same date in every directory gets proccesed to 1 file.</p>
  <p>This is my code:</p>
  <pre><code>missing_dates = ['20200907', '20200908', '20200909']
  
  root=Path(r'c:\data\FF\Desktop\new_location\middle_stage_preprocessed_district')
  
  data_per_date = dict()
  for missing_date in missing_dates:
      print(f&quot;processing {missing_date}&quot;)
      files=[fn for fn in (e for e in root.glob(f&quot;**/*_{missing_date}.txt&quot;) if e.is_file())]
      if len(files) != 3:
          # stop processing, check other date
          continue
  
      for file in files:
          with open(file, 'r') as log_file:
              reader = csv.reader(log_file, delimiter = ',')
              next(reader) # skip header
              for row in reader:
                  if filter_row(row):
                      vehicle_loc_dict[(row[9], location_token(row))].append(row)
  
      data_per_date[missing_date] = vehicle_loc_dict  
                                                                                               
  for date in missing_dates:
      file_name = &quot;MM{}-AB.dat&quot;.format(date)
      full_path = os.path.join(my_files, 'Directory_X', file_name)
      with open(full_path, 'w+') as output:
          writer = csv.writer(output, delimiter = '\t')
          writer.writerow(headers)
          writer.writerow(data)
          vehicle_loc = data_per_date[date]
          for vehicle_loc_list in vehicle_loc.values():
              for record_group in group_records(vehicle_loc_list):
                  writer.writerow(output_record(record_group))
  </code></pre>
  <p>My file structure is like this:</p>
  <pre><code>├── dir_1
  │   ├── XX_20200907.txt
  │   └── XX_20200908.txt
  ├── dir_2
  │   ├── YY_20200907.txt
  │   └── YY_20200908.txt
  └── dir_3
      ├── ZZ_20200907.txt
      └── ZZ_20200908.txt
  </code></pre>
  <p>I receive below error, but I dont know why.</p>
  <pre><code>Traceback (most recent call last):
  
    File &quot;C:\data\FF\Desktop\Python\Python\Official_part1.py&quot;, line 271, in &lt;module&gt;
      vehicle_loc = data_per_date[date]
  
  KeyError: '20200909'
  </code></pre>