python get name of all files in directory code example
Example 1: python get all file names in directory
import glob
print(glob.glob("/home/adam/*.txt"))
Example 2: get files in directory python
import os
files_and_directories = os.listdir("path/to/directory")
Example 3: get file names in folder python
from os import listdir
from os.path import isfile, join
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
Example 4: python dir all files
import os
for root, dirs, files in os.walk("."):
for filename in files:
print(filename)