title: How to open a file by using a regular expression in python
body: <p>I need to search for a pattern like (Error, Warning, Severity) in a file, This file will be located in a particular folder (e.g. <code>D:\express\abc_xyz_9.0_12_9_17_23_11.log</code>), the problem here is every time, when i install the software, the file will be generated based on the date and time of the system, so i can't hard code the file name, I need to write a regular expression to find the filename and open it and search for a pattern, here is the code, I have tried, but it throws an error as </p>
  
  <pre><code>TypeError: expected str, bytes or os.PathLike object, not list
  </code></pre>
  
  <p>Please find below to check for my code,</p>
  
  <pre><code>import os
  
  path = os.listdir("D:\Express")
  print(path)
  with open(path) as f:
      for line in f:
          if python in f:
              print (line)
  </code></pre>