1import os
2
3files = os.listdir('.')
4print(files)
5for file in files:
6 # do something
7
1from pathlib import Path
2for txt_path in Path("/path/folder/directory").glob("*.txt"):
3 print(txt_path)
1from os import listdir
2from os.path import isfile, join
3onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
4
1(_, _, filenames) = os.walk(mypath).next() #if you are confident that the walk will return at least one value