不知道是我移动硬盘里文件太多还是什么原因,everything迟迟读不出文件。。于是可能要放弃everything 使用别的方法搜索文件了。然后突然想到,其实everything如果每次都搜索的话,其实很浪费时间,大部分文件其实都是不会变位置的,虽说他也有缓存吧,但是插入了移动硬盘之后,他又要重新搜索了。所以其实要做个能用就行的文件搜索,只要把遍历出来的文件路径放到一个txt里就行,以后要找文件,就直接搜这个文件的字符串,于是找到这个代码
然后改一下就行
def make_files_lst(path,res_list,ignore_dir_lst):
try:
lsdir = os.listdir(path)
except Exception as e:
print(e)
return
dirs = [i for i in lsdir if os.path.isdir(os.path.join(path, i))]
if dirs:
for i in dirs:
if i in ignore_dir_lst:
continue
# print_files(os.path.join(path, i))
make_files_lst(os.path.join(path, i),res_list,ignore_dir_lst)
files = [i for i in lsdir if os.path.isfile(os.path.join(path, i))]
for f in files:
abs_path = os.path.join(path, f)
res_list.append(abs_path)
path=r"G:"
make_files_lst(path,res_list)
# print(res_list)
out_str+=path+"\n"
for i in res_list:
out_str+=i+"\n"
with open("findFileG.txt","w" ,encoding="utf-8") as f:
f.write(out_str)