# use endswith(".extension") import os for file in os.listdir("/mydir"): if file.endswith(".txt"): print(os.path.join("/mydir", file))