python os find all files in directory code example
Example 1: how to search for a specific file extension with python
import glob, os
os.chdir("/mydir")
for file in glob.glob("*.txt"):
print(file)
Example 2: python get all file names in directory
import glob
print(glob.glob("/home/adam/*.txt"))
Example 3: python dir all files
import os
for root, dirs, files in os.walk("."):
for filename in files:
print(filename)