title: I am having problems reading multiple txt files
body: <p>I am having a trouble when I try to read multiple text files in python.
  I'm trying to get only IP addresses from text files. When I try with a single text file, it works fine. However, when I copy more than one text file to the folder, I only get the output of the first file.</p>
  <pre><code>import os
  import re
  import glob
  
  
  
  path = &quot;file_direction&quot;
  pattern = re.compile(r'(?:(?:1\d\d|2[0-5][0-5]|2[0-4]\d|0?[1-9]\d|0?0?\d)\.){3}(?:1\d\d|2[0-5][0-5]|2[0-4]\d|0?[1-9]\d|0?0?\d)')
  valid = []
  invalid = []
  
  
  
  for path in glob.glob(os.path.join(path, &quot;*.txt&quot;)):
      with open(path, mode=&quot;r&quot;, encoding=&quot;utf-8&quot;) as fh:
          string = fh.readlines()
  
  
  for line in string:
      line = line.rstrip()
      result = pattern.search(line)
  
      # valid IP addresses
      if result:
          valid.append(line)
  
      # invalid IP addresses
      else:
          invalid.append(line)
  
  # displaying the IP addresses
  print(&quot;Valid IPs&quot;)
  print(valid)
  print(&quot;Invalid IPs&quot;)
  print(invalid)
  </code></pre>