Jan-16-2020, 06:40 PM
I can't run the following code as I don't use windows, but this should list all csv files in all directories
within and below a root directory of D:\data\project\*\*\InputFiles (you will have to supply actual values for '*')
within and below a root directory of D:\data\project\*\*\InputFiles (you will have to supply actual values for '*')
from pathlib import Path def walk_dir(starting_dir): flist = [] for path in Path(starting_dir).iterdir(): if path.is_file(): if path.suffix == '.csv': print(path) flist.append(path) elif path.is_dir(): walk_dir(path) for file in flist: print(file) if __name__ == '__main__': start_path = 'D:\data\project\*\*\InputFiles' import os os.chdir(os.path.abspath(os.path.dirname(__file__))) srcdir = Path('.') savefile = srcdir / 'allcsvfiles.txt' walk_dir(start_path, savefile)