title: Unable to open or read log files: FileNotFoundError
body: <p>This should be fairly simple, but I just can't figure it out. I'm trying to iterate over a list of files to find a specific phrase within the files, and then print the filename(s) that contain the phrase.</p>
  <p>It reads the path fine, and adds the files to a list, then prints the list of files, but when I try to open each one to search for the phrase, I get &quot;FileNotFoundError: [Errno 2] No such file or directory:&quot;</p>
  <pre><code>import os 
  
  FILENAMES = []
  FILE_COUNT = 0
  dir_path = r&quot;C:\Users\me\Documents\Python Scripts\Log Parsing\Logs&quot;
  
  
  for root, dirs, files in os.walk(dir_path):
      # print(files)
  
      for filename in files:
          FILENAMES.append(filename)
          FILE_COUNT += 1
          print(filename)
      print(FILE_COUNT)
  
  for filename in FILENAMES:
      print(filename,&quot; contains the following string:\n&quot;)
      f = open(filename, 'r')
      for line in f:
          if (&quot;their browser&quot;) in line:       # search for specific phrase within file
              print(line)
          else:
              pass
      print('\n')
      f.close()
  </code></pre>
  <blockquote>
  <p>Below is the output:</p>
  <p>server.log_2022-07-05T16-47-42 server.log_2022-07-05T20-43-09
  server.log_2022-07-06T10-54-28 server.log_2022-07-06T14-16-51
  server.log_2022-07-06T15-12-06 server.log_2022-07-06T15-31-42
  server.log_2022-07-06T16-06-15 server.log_2022-07-06T16-34-07
  server.log_2022-07-06T17-00-03 server.log_2022-07-06T17-15-50
  server.log_2022-07-06T17-34-18 server.log_2022-07-06T17-48-16
  server.log_2022-07-07T08-08-16 272 server.log_2022-02-12T08-09-29
  contains the following string:</p>
  <p>Traceback (most recent call last):   File
  &quot;c:\Users\me\Documents\Python Scripts\Log
  Parsing\Logs\logs_v4.py&quot;, line 19, in 
  f = open(filename, 'r') FileNotFoundError: [Errno 2] No such file or directory: 'server.log_2022-02-12T08-09-29'</p>
  </blockquote>
  <p>It's obviously reading the filenames. I don't understand FileNotFoundError.</p>