I have to loop through a large number of folder at a given path (My_Path
) (around 60 000).
Then in each folder in My_Path
, I have to check if a file name contains a certain date.
I want to know if there is a faster way than looping one by one using the os
library. (Around 1 hour)
My_Path:
- Folder 1
o File 1
o File 2
o File 3
o …
- Folder 2
- Folder 3
- …
- Folder 60 000
import os
My_Path = r'\\...\...\...\...'
mylist2 = os.listdir(path) # give a list of 60000 element
for folder in mylist2:
mylist = os.listdir(My_Path + folder) # give the list of all files in each folder
for file in mylist:
Check_Function(file)
The actual run takes around one hour and I want to know if there is an optimal solution.
Thanks !!