python get list of files in folder code example
Example 1: python list files in current directory
import os
files = os.listdir('.')
print(files)
for file in files:
Example 2: list files in directory python
import os
print(os.listdir('/path/to/folder/to/list'))
Example 3: list files python
import glob
files=glob.glob(given_path)
Example 4: read all files in folder python
import glob
print(glob.glob("/home/adam/*.txt"))
Example 5: get list of files in directory python
import os
path = '/folder1/folder2/'
files = os.listdir(path)