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

python迭代查找目录下文件

时间:2015-05-14 20:48:06      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:python   files   

#两种方法
#!/usr/bin/env python
import os

dir=‘/root/sh‘
‘‘‘
def fr(dir):
  filelist=os.listdir(dir)
  for i in filelist:
    fullfile=os.path.join(dir,i)
    if not os.path.isdir(fullfile):
      if i == "1.txt":
        #print fullfile
	os.remove(fullfile)
    else:
      fr(fullfile)

‘‘‘

‘‘‘
def fw()dir:
  for root,dirs,files in os.walk(dir):
    for f in files:
      if f == "1.txt":
        #os.remove(os.path.join(root,f))
        print os.path.join(root,f)
‘‘‘


python迭代查找目录下文件

标签:python   files   

原文地址:http://yayang.blog.51cto.com/826316/1651279

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