python迭代查找目录下文件
时间:2015-05-14 20:48:06
收藏:0
阅读:205
#两种方法 #!/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) ‘‘‘
评论(0)