|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- import os
- def search_file(start_dir, target) :
- os.chdir(start_dir)
-
- for each_file in os.listdir(os.curdir) :
- if each_file == target :
- print(os.getcwd() + os.sep + each_file) # 使用os.sep是程序更标准
- if os.path.isdir(each_file) :
- search_file(each_file, target) # 递归调用
- os.chdir(os.pardir) # 递归调用后切记返回上一层目录
- start_dir = input('请输入待查找的初始目录:')
- target = input('请输入需要查找的目标文件:')
- search_file(start_dir, target)
复制代码
上面是小甲鱼的参考答案,可是我运行了却显示
Traceback (most recent call last):
File "<pyshell#10>", line 3, in <module>
search_file(each_file, target) # 递归调用
File "<pyshell#2>", line 8, in search_file
search_file(each_file, target) # 递归调用
File "<pyshell#2>", line 8, in search_file
search_file(each_file, target) # 递归调用
File "<pyshell#2>", line 8, in search_file
search_file(each_file, target) # 递归调用
File "<pyshell#2>", line 4, in search_file
for each_file in os.listdir(os.curdir) :
PermissionError: [WinError 5] 拒绝访问。: '.'
请问是哪儿出问题了呀
你是不是访问C盘这类东西了,py没有权限的,换个盘试试
|
|