删除目录下的所有".svn"文件

时间:2022-08-26 12:08:39

丢一段python代码:

# -*- coding: cp936 -*-
import os
import re
import shutil

'''找出路径base(包括子目录)下所有符合pattern(正则表达式)的文件夹或文件'''
def find_file(base='.',pattern='^.*$'):
    re_file = re.compile(pattern)
    if base == '.':
        base = os.getcwd()
    final_file_list = []
    cur_list = os.listdir(base)
    for item in cur_list:
        full_path = os.path.join(base,item)
        if re_file.search(item):
            final_file_list.append(full_path)
        elif os.path.isdir(full_path):
            final_file_list += find_file(full_path,pattern)
    return final_file_list

svnDirs = find_file(".","^.svn$")
print os.getcwd()
print "removing..."
for dirname in svnDirs:
    print dirname
    shutil.rmtree(dirname)
print "ok"