How to get list of files in directory with extension with Python

Python glob module finds all the pathnames matching a specified pattern.

import glob, os
os.chdir("/my_directory")
for file in glob.glob("*.zip"):
    print(file)
  • N.B.! The results are returned in arbitrary order.
  • Note that glob module is built in and does not require any modules to work.