Search notes:

Python standard library: glob

Python standard library glob: find filenames with wildcards.

Simple example

import os
import sys
import glob

if len(sys.argv) < 3:

   print
   print "Usage       ", sys.argv[0], " dir suffix"
   print 'For example ', sys.argv[0], ' c:\\temp txt'
   exit

dir_   = sys.argv[1]
suffix = sys.argv[2]

os.chdir (dir_)

matched_files = glob.glob("*." + suffix)

print "\n".join(matched_files)
Github repository about-python, path: /standard-library/glob/glob.py

See also

os.walk creates a generator that produces a directory's subdirectories and their files.
os.scandir() and os.listdir()
standard library

Index