Python递归查找文件(os.walk, os.path, fnmatch)

#!/usr/bin/env python
#coding=utf8
'''
Python ver 2.7
Search some file recursivily
'''
import os
import fnmatch

def recursiveSearchFile(searchPath, partInfo):
    wantFilesPath = []
    for (dirPath, dirNames, fileNames) in os.walk(searchPath):
         wantFilesPath += [os.path.join(dirPath, fileName) for fileName in fileNames if fnmatch.fnmatch(os.path.join(dirPath, fileName), partInfo)]
    return wantFilesPath

if __name__ == "__main__":
    fileList = recursiveSearchFile('C:\\Users\Administrator\\Desktop', '*.pl')
    for path in fileList:
        print path 
posted @ 2015-10-13 11:29  笑面浮屠  阅读(296)  评论(0编辑  收藏  举报