import glob, os os.chdir("/mydir") for file in glob.glob("*.txt"): print(file)
Here is what the above code is Doing:
1. Change the current working directory to /mydir
2. Find all files ending with .txt in /mydir
3. Print the names of those files to the screen, one name per line