load all files from a directory in python code example
Example 1: python read a directory to get all files in sub folders
import os
path ="C:/workspace/python"
filelist = []
for root, dirs, files in os.walk(path):
for file in files:
filelist.append(os.path.join(root,file))
for name in filelist:
print(name)
Example 2: python import all files in directory
import glob
import os
directory = '/path/to/directory/with/files/'
all_files = glob.glob(os.path.join(directory, "*.txt"))
your_list = [ ]
for filename in all_files:
dataframe = pd.read_csv(filename, index_col=None, header=0, sep="\t")
your_list.append(dataframe)