码迷,mamicode.com
首页 > 编程语言 > 详细

Python文件查找

时间:2014-10-14 23:48:49      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:io   os   for   文件   sp   div   on   cti   ef   

#!/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文件查找

标签:io   os   for   文件   sp   div   on   cti   ef   

原文地址:http://www.cnblogs.com/L-H-R-X-hehe/p/4025281.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!