title: How do I get some(5) list of files in a directory and subfolders in Python?
body: <p>How do I get some list of files in a directory and sub_folders in Python?
  I want to get only 5 .txt files in each directory.</p>
  
  <p>I've been searched a lot, but can not find answer.</p>
  
  <p>Need your help.</p>
  
  <p>I've been testing Path, glob, os.walk().</p>
  
  <pre><code>import os
      for files in Path(".").glob(extension):
          print(files)
  </code></pre>
  
  <p>print all the list of file with extension</p>
  
  <pre><code>import os
      cpt = sum([len(files) for r, d, files in os.walk(".")])
      cpt = [len(files) for r, d, files in os.walk(dpath)]
      print(cpt)
  
  [5, 25, 3, 0, 0, 1, 2, 2, 0, 0, 0, 8, 8, 4, 16, 4, 8]
  </code></pre>
  
  <p>Now all files, But 5 files in each directory.</p>