关于python的问题及解答_关于python的一个报错问题

一个类似于输关键词然后找文件的程序

请问各位大佬,这个报错是什么意思呢,还有就是这个语句要怎么改呢

#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']"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值