一个类似于输关键词然后找文件的程序
请问各位大佬,这个报错是什么意思呢,还有就是这个语句要怎么改呢
#search_disk_test
import os
a=input("please enter the key words you want to search: ")
for root,dirs,files in os.walk("C:\\"):
if os.path.getsize(os.path.abspath(str(files))) or os.path.getsize(os.path.abspath(str(dirs))) or os.path.getsize(os.path.abspath(str(root)))==0:
pass
else:
if os.path.splitext(os.path.abspath(str(files)))==".py"or".txt"or".doc"or".docx":
if str(os.path.basename(str(files))).find(str(a))!=-1:
print(os.path.abspath(str(files)))
with open(os.path.abspath(str(files)),"r",encoding="gbk",errors="ignore")as file_search:
t=file_search.read()
if t.find(str(a))==-1:
print(a+"is not exists in "+os.path.basename(str(files)))
if t.find(str(a))!=-1:
print(a+"is exists in "+os.path.basename(str(files)))
else:
print(str(os.path.basename(str(files)))+" may not be your target,but we will still check the content of it")
with open(os.path.abspath(str(files)),"r",encoding="gbk",errors="ignore") as file_search:
t=file_search.read()
if t.find(str(a))==-1:
print(a+"is not exists in "+os.path.basename(str(files)))
if t.find(str(a))!=-1:
print(a+"is exists in "+os.path.basename(str(files)))
else:
print(os.path.basename(str(files)))
if str(os.path.basename(str(files))).find(str(a))==-1:
print("not exists "+str(os.path.basename(str(files))))
else:
print("these may be the file you are finding: "+str(os.path.basename(str(files))))
以下是报错:
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
============= RESTART: D:\python\python_work\search_disk_test.py =============
please enter the key words you want to search: abc
Traceback (most recent call last):
File "D:\python\python_work\search_disk_test.py", line 5, in
if os.path.getsize(os.path.abspath(str(files))) or os.path.getsize(os.path.abspath(str(dirs))) or os.path.getsize(os.path.abspath(str(root)))==0:
File "D:\python\lib\genericpath.py", line 50, in getsize
return os.stat(filename).st_size
FileNotFoundError: [WinError 2] 系统找不到指定的文件。: "D:\\python\\python_work\\['bootmgr', 'BOOTNXT', 'hiberfil.sys', 'pagefile.sys', 'swapfile.sys']"