get a list of all files in directory python code example
Example 1: python get files in directory
from pathlib import Path
for txt_path in Path("/path/folder/directory").glob("*.txt"):
print(txt_path)
Example 2: list files python
import glob
files=glob.glob(given_path)
Example 3: list directory in python
from os import listdir
## Prints the current directory as a list (including file types)
print(os.listdir())