import os def fn(s,d): for f in os.listdir(d): path=os.path.join(d,f) if os.path.isfile(path): if s in f: print(f,path) else: fn(s,path) fn('xyz',D:\\test)
在这里os.path.isfile(x)中的x参数一定要绝对路径才能判断
其实os.path.isdir(path)也要是绝对路径,否则当前目录的子子目录是查不出来的,只能查到子目录
Sign in to make a reply
牙神牙拔
在这里os.path.isfile(x)中的x参数一定要绝对路径才能判断