编写一个search(s)的函数,能在当前目录以及当前目录的所有子目录下查找文件名包含指定字符串的文件,并打印出完整路径:
def search(dir,w):
for x in os.listdir(dir):
nf=os.path.join(dir,x)
if os.path.isfile(nf) and w in nf:
print nf
elif os.path.isdir(nf):
search(nf,w)
search('.','test')
转载于:https://blog.51cto.com/yayang/1616367