码迷,mamicode.com
首页 > 其他好文 > 详细

os.walk

时间:2015-03-31 20:21:41      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:walk

for i in os(‘/tmp‘):

for i in os.walk(‘/tmp‘):
...   print i
...
(‘/tmp‘, [‘lost+found‘, ‘hsperfdata_richmail‘, ‘.ICE-unix‘], [‘tmpping.txt‘, ‘hkm‘])
(‘/tmp/hsperfdata_richmail‘, [], [])
(‘/tmp/.ICE-unix‘, [], [])

 

 

def walk_search(path,filename):
    store_file_list=[]
    for root,dir_list,file_list in os.walk(path):
        if file_list is not None:
            for  f1 in file_list:
                if f1.startswith(filename):
                   store_file_list.append(f1)
    return store_file_list
print walk_search("/home/richmail/logs",‘richmailsvr‘)

 

[‘richmailsvr.log.2015-03-31‘, ‘richmailsvr.log‘, ‘richmailsvr.log.2015-03-30‘, ‘richmailsvr.log.2015-02-17.gz‘, ‘richmailsvr.log.2015-01-04.gz‘, ‘richmailsvr.log.2015-03-22.gz‘, ‘richmailsvr.log.2015-01-09.gz‘, ‘richmailsvr.log.2015-02-16.gz‘, ‘richmailsvr.log.2015-02-20.gz‘, ‘richmailsvr.log.2015-02-05.gz‘, ‘richmailsvr.log.2015-01-20.gz‘, ‘richmailsvr.log.2015-01-26.gz‘, ‘richmailsvr.log.2015-03-11.gz‘, ‘richmailsvr.log.2015-03-17.gz‘, ‘richmailsvr.log.2015-03-09.gz‘, ‘richmailsvr.log.2015-01-31.gz‘, ‘richmailsvr.log.2015-03-29.gz‘, ‘richmailsvr.log.2015-01-25.gz‘, ‘richmailsvr.log.2015-01-05.gz‘, ‘richmailsvr.log.2015-03-15.gz‘, ‘richmailsvr.log.2015-03-28.gz‘, ‘richmailsvr.log.2015-02-26.gz‘, ‘richmailsvr.log.2015-02-07.gz‘, ‘richmailsvr.log.2015-01-30.gz‘, ‘richmailsvr.log.2015-02-12.gz‘, ‘richmailsvr.log.2015-03-10.gz‘, ‘richmailsvr.log.2015-03-14.gz‘, ‘richmailsvr.log.2015-03-03.gz‘, ‘richmailsvr.log.2015-03-24.gz‘, ‘richmailsvr.log.2015-03-13.gz‘, ‘richmailsvr.log.2015-02-23.gz‘, ‘richmailsvr.log.2015-02-08.gz‘, ‘richmailsvr.log.2015-01-13.gz‘, ‘richmailsvr.log.2015-02-21.gz‘, ‘richmailsvr.log.2015-02-03.gz‘, ‘richmailsvr.log.2015-02-02.gz‘, ‘richmailsvr.log.2015-03-01.gz‘, ‘richmailsvr.log.2015-01-01.gz‘, ‘richmailsvr.log.2015-01-19.gz‘, ‘richmailsvr.log.2015-01-16.gz‘, ‘richmailsvr.log.2015-01-06.gz‘, ‘richmailsvr.log.2015-02-04.gz‘, ‘richmailsvr.log.2015-03-27.gz‘, ‘richmailsvr.log.2015-02-28.gz‘, ‘richmailsvr.log.2015-01-07.gz‘, ‘richmailsvr.log.2015-03-18.gz‘, ‘richmailsvr.log.2015-03-07.gz‘, ‘richmailsvr.log.2015-01-11.gz‘, ‘richmailsvr.log.2015-03-16.gz‘, ‘richmailsvr.log.2015-02-22.gz‘, ‘richmailsvr.log.2015-01-28.gz‘, ‘richmailsvr.log.2015-03-06.gz‘, ‘richmailsvr.log.2015-01-27.gz‘, ‘richmailsvr.log.2015-03-23.gz‘, ‘richmailsvr.log.2015-03-04.gz‘, ‘richmailsvr.log.2015-01-21.gz‘, ‘richmailsvr.log.2015-01-23.gz‘, ‘richmailsvr.log.2015-03-19.gz‘, ‘richmailsvr.log.2014-12-30.gz‘, ‘richmailsvr.log.2015-01-12.gz‘, ‘richmailsvr.log.2015-03-08.gz‘, ‘richmailsvr.log.2015-03-25.gz‘, ‘richmailsvr.log.2015-02-01.gz‘, ‘richmailsvr.log.2015-01-17.gz‘, ‘richmailsvr.log.2015-02-25.gz‘, ‘richmailsvr.log.2015-02-27.gz‘, ‘richmailsvr.log.2015-03-26.gz‘, ‘richmailsvr.log.2015-01-15.gz‘, ‘richmailsvr.log.2015-02-10.gz‘, ‘richmailsvr.log.2015-02-19.gz‘, ‘richmailsvr.log.2015-01-10.gz‘, ‘richmailsvr.log.2015-03-21.gz‘, ‘richmailsvr.log.2015-02-18.gz‘, ‘richmailsvr.log.2015-01-22.gz‘, ‘richmailsvr.log.2015-01-29.gz‘, ‘richmailsvr.log.2015-03-12.gz‘, ‘richmailsvr.log.2015-03-05.gz‘, ‘richmailsvr.log.2015-01-02.gz‘, ‘richmailsvr.log.2014-12-31.gz‘, ‘richmailsvr.log.2015-02-09.gz‘, ‘richmailsvr.log.2015-01-14.gz‘, ‘richmailsvr.log.2015-01-03.gz‘, ‘richmailsvr.log.2015-02-14.gz‘, ‘richmailsvr.log.2015-02-11.gz‘, ‘richmailsvr.log.2015-01-24.gz‘, ‘richmailsvr.log.2015-02-13.gz‘, ‘richmailsvr.log.2015-02-24.gz‘, ‘richmailsvr.log.2015-02-06.gz‘, ‘richmailsvr.log.2015-01-08.gz‘, ‘richmailsvr.log.2015-03-20.gz‘, ‘richmailsvr.log.2015-02-15.gz‘, ‘richmailsvr.log.2015-03-02.gz‘, ‘richmailsvr.log.2015-01-18.gz‘]

本文出自 “歪歪男生乖乖心” 博客,请务必保留此出处http://iamxiao.blog.51cto.com/6530374/1626960

os.walk

标签:walk

原文地址:http://iamxiao.blog.51cto.com/6530374/1626960

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