#-*- coding:gbk -*-
'''
Created on 2012-3-13
@author: Czp
'''
import os
import shutil
class FindWord(object):
'''
Find the keyWork in input path
'''
def __init__(self):
'''
Constructor
'''
def _find(self,keyWord,dirName,fileList):
# print 'search ['+dirName+']'
keyWord = unicode(keyWord,'GBK')
for file in fileList:
path = os.path.join(dirName,file)
if os.path.isdir(path) and keyWord in path:
shutil.rmtree(path);
print 'find '+keyWord+' in '+path
def start(self,path,keyWord):
if os.path.exists(path):
os.path.walk(path, self._find, keyWord)
else:
print 'the path not exist'
if __name__=='__main__':
try:
fw = FindWord()
fw.start('D:\Myprogram\backUP','.svn')
except Exception,e:
以上就是本篇文章【python查找word关键词_Python 在指定的目录下搜索包含关键字的文件】的全部内容了,欢迎阅览 ! 文章地址:http://keair.bhha.com.cn/news/710.html
文章
相关文章
动态
同类文章
热门文章
栏目首页
网站地图
返回首页 康宝晨移动站 http://keair.bhha.com.cn/mobile/ , 查看更多