title: Text Files Being Read in a Really Weird Manner
body: <p>I'm using <a href="https://www.geeksforgeeks.org/how-to-read-multiple-text-files-from-folder-in-python/" rel="nofollow noreferrer">this code</a> which reads every text file in a given directory:</p>
  <pre><code># Import Module
  import os
    
  # Folder Path
  path = &quot;Enter Folder Path&quot;
    
  # Change the directory
  os.chdir(path)
    
  # Read text File
    
    
  def read_text_file(file_path):
      with open(file_path, 'r') as f:
          print(f.read())
    
    
  # iterate through all file
  for file in os.listdir():
      # Check whether file is in text format or not
      if file.endswith(&quot;.txt&quot;):
          file_path = f&quot;{path}\{file}&quot;
    
          # call read text file function
          read_text_file(file_path)
  </code></pre>
  <p>The problem is, is that it's not reading each datafile chronologically (data1.txt, data2.txt, data3.txt, etc), but instead is reading each file in a really weird way (data1.txt, data10.txt, data101.txt, data2.txt, etc).</p>
  <p>Why the hell is it doing this, and how do I fix it?</p>