編寫一個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')
編寫一個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')