Discuss / Python / 递归搜索

递归搜索

Topic source

ASAPUo

#1 Created at ... [Delete] [Delete and Lock User]

import os

def searchFile(key,path): getAll = os.listdir(path) for f in getAll: subpath = os.path.join(path,f) if os.path.isdir(subpath): searchFile(key,subpath) elif os.path.isfile(subpath) and key in f: print('file in %s : %s' % (path,f)) else: pass

searchFile('test','E:\Python')

ASAPUo

#2 Created at ... [Delete] [Delete and Lock User]

<div> <pre> <code> import os def searchFile(key,path): getAll = os.listdir(path) for f in getAll: subpath = os.path.join(path,f) if os.path.isdir(subpath): searchFile(key,subpath) elif os.path.isfile(subpath) and key in f: print('file in %s : %s' % (path,f)) else: pass </code> </pre> </div>


  • 1

Reply