Discuss / Python / 用递归没有用walk()函数实现第二题

用递归没有用walk()函数实现第二题

Topic source

ssdsd_61705

#1 Created at ... [Delete] [Delete and Lock User]
在此插入代码

import os tofind = input('请输入要查找的文件名\n')

def find_file(paths, to_find): dirname = os.path.abspath(paths) # 得到当前目录,isfile和isdir必须用绝对路径才能判断,否则返回false for f in os.listdir(paths): absfile = os.path.join(dirname, f) if os.path.isfile(absfile): if to_find in f: print(f) elif os.path.isdir(absfile): find_file(absfile, to_find)

find_file('.', tofind)


  • 1

Reply