import os
#当前路径
cur_dir = os.path.dirname(os.path.abspath(__name__))
print(cur_dir)
#副路径目录
parent_dir = os.path.dirname(cur_dir)
print(parent_dir)
find_path,file_path = os.path.join(parent_dir,'FTP'),None
while 1:
find_file_name = input(f'请提示你想在{find_path}中查找的文件名:')
if find_file_name == 'q':
break
file_exists = False
for root,dirs,files in os.walk(find_path):
for item in files:
if item == find_file_name:
file_exists=True
file_path = os.path.join(root,item)
break
if file_exists:
print(f'找到了{file_path}')
else:
print('没找到')
递归查找在文件夹内的某个文件
最新推荐文章于 2024-07-21 09:49:59 发布