I am tryin to find the specific files in the folder directory which is complicated. Let me show the directories
This is the Final File Directory
This is the First Folder Directory
This is the Second Folder Directory1
This is the Second Folder Directory2
I need to find each and every folders that has the "_Caminfo.dat" and "running.csv" both files init or not
This is the codes I tried
import glob
FP= "D:\python_workspace-shim\copied_data/*" ## FP = File Path
FL = glob.glob(FP)
FN = ["_Caminfo.dat", "running.csv"] ## the specific files I want to find
for i in range(0, len(FL)):
FP2 = FP2 = glob.glob(FL[i] "/*")
for j in range(0, len(FN)):
FN2 = FN[j]
for k in range(0, len(FP2)):
adr = FP2[k] '/0000/02_output/' FP2[k][37:39] FP2[k][40:42] '0000/' FN2 ## adr = Address
FN3 = glob.glob(adr)
for len(FN2) in adr:
if len(FN2) not in adr:
print(FN3)
CodePudding user response:
The below code will output all folder paths that contains one of those 2 files, the list is sorted to make reading the output easier.
from glob import glob
path = "Parent folder path"
list_files = glob(path "\\**\\_CamInfo.dat", recursive = True) glob(path "\\**\\running.csv", recursive = True)
print(*sorted(list_files), sep="\n")