放在整齐的目录,遍历优化速度优化7倍:
0.9秒
start=time.time()
dirs=glob.glob(box_root+'/*')
pkl_name='data_box.pkl'
ok_num=0
sense_files=[]
for dir in dirs:
file_path=dir+f'/{pkl_name}'
if os.path.exists():
ok_num+=1
sense_files.append(file_path)
print(len(sense_files),'time_find_files',time.time()-start)
6.7秒
sense_files = ['%s/%s' % (i[0].replace("\\","/"), j) for i in os.walk(box_root) for j in i[-1] if j.endswith(('data_box.pkl', 'apng', 'ajpeg'))]
sense_files.sort()