首页 > 代码库 > Python文件查找

Python文件查找

#!/usr/bin/python
 
import os
import string
 
def get_name(path_name, file_str):
        dir_name = []
        dir_name = os.listdir(path_name)
        for i in range(0, len(dir_name)):
                curdir = os.path.join(path_name, dir_name[i])
                if os.path.isdir(curdir):
                        if file_str in dir_name[i]:
                                print ‘DIR:‘ + curdir
                        get_name(curdir, file_str)
                else:
                        if file_str in dir_name[i]:
                                print ‘FILE:‘ + curdir
 
 
file_name = raw_input("Input file name:")
path = raw_input("Input path:")
 
get_name(path, file_name)

Python文件查找