【发布时间】:2019-09-03 14:12:48
【问题描述】:
我必须遍历给定路径 (My_Path) 的大量文件夹(大约 60 000 个)。
然后在My_Path 的每个文件夹中,我必须检查文件名是否包含某个日期。
我想知道是否有比使用os 库逐个循环更快的方法。 (约 1 小时)
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)
实际运行大约需要一个小时,我想知道是否有最佳解决方案。
谢谢!!
【问题讨论】:
-
Python 说变量名和函数名不能大写,请改用
my_path和check_function。大写字母保留给类名。
标签: python