|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 是BB啊 于 2021-4-21 16:02 编辑
import os
def file_find(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)
if os.path.isfile(each_file):
file_find(each_file, target)
os.chdir(os.pardir)
start_dir = input('请输入待查找的初始目录:')
target = input('请输入需要查找的目标文件:')
file_find(start_dir, target)
>>>
请输入待查找的出视目录:D:\\python\\试着写
请输入需要查找的目标文件:20.1
Traceback (most recent call last):
File "D:\python\试着写\30.2.py", line 13, in <module>
file_find(start_dir, target)
File "D:\python\试着写\30.2.py", line 8, in file_find
file_find(each_file, target)
File "D:\python\试着写\30.2.py", line 3, in file_find
os.chdir(start_dir)
NotADirectoryError: [WinError 267] 目录名称无效。: '(20.1).py'
为什么目录名称失效呢
|
|