Is there a way to list the files (not directories) in a directory with Python? I know I could use os.listdir
and a loop of os.path.isfile()
s, but if th
Using pathlib in Windows as follow:
files = (x for x in Path("your_path") if x.is_file())
Generates error:
TypeError: 'WindowsPath' object is not iterable
You should rather use Path.iterdir()
filePath = Path("your_path")
if filePath.is_dir():
files = list(x for x in filePath.iterdir() if x.is_file())