Jun-25-2019, 03:05 PM
My files in folders are structures as follows:
Folder1
Filea
Fileb
Filec
Folder2
Filea
Fileb
Filec
Folder3
Filea
Fileb
Filec
I am trying to loop through each folder and build a list of the files with the path directory so that I can pass this list to another function that will process each list of files with the same name as the idea is I need to in the end combine the data from files with the same name.
I am struggling to get the logic right because I am not sure how am I going to pass the list of [path1_filea, path2_filea,path3_filea] and the pass the next list of files [path1_fileb, path2_fileb, path3_file] so that the next function will process each list one by one.
Folder1
Filea
Fileb
Filec
Folder2
Filea
Fileb
Filec
Folder3
Filea
Fileb
Filec
I am trying to loop through each folder and build a list of the files with the path directory so that I can pass this list to another function that will process each list of files with the same name as the idea is I need to in the end combine the data from files with the same name.
1 2 3 4 5 6 7 8 9 10 11 12 |
file_list = [] for filename in os.listdir(path): print (filename) for root, dirs,files in os.walk(path1): for f in files: print (f) if f = = filename: fullpath = os.path.join(root,f) filename = os.path.basename(fullpath) filelist = file_list.append(fullpath) #print(filelist) |