[工具]删除目录及子目录下的所有.svn目录

说明:此工具只适用于win32系统,如xp, win7


第一步:下载并安装Python

下载地址:http://www.python.org,下载Python2.7


第二步:下载并安装pywin32

下载地址:http://sourceforge.net/projects/pywin32/files/pywin32/Build%20218/

下载的是pywin32-218.win32-py2.7.exe


第三步:将以下代码保存为delSVN.py文件,然后双击运行,粘贴目录的路径。

import os, platform, sys

WIN32 = 'win32'
SVN = '.svn'

class Util:

    @staticmethod
    def checkSystem():
        system = platform.system()
        if system == 'Windows':
            return WIN32

    @staticmethod
    def validatePath(path):
        if os.path.isdir(path):
            return True
        else:
            return False

class SVNDeleter:

    def __init__(self):
        self.ifSuccess = True

    def delete_folder(self, path):
        for item in os.listdir(path):
            itemPath = os.path.join(path,item)
            win32api.SetFileAttributes(itemPath, win32con.FILE_ATTRIBUTE_NORMAL)
            if os.path.isdir(itemPath):
                self.delete_folder(itemPath)
            else:
                print 'remove', itemPath
                try:
                    os.remove(itemPath)
                except:
                    self.ifSuccess = False

        print 'remove', path
        try:
            os.rmdir(path)
        except:
            self.ifSuccess = False

    def delete_svn_folder(self, tree):
        if os.path.isdir(tree):
            for item in os.listdir(tree):
                itemPath = os.path.join(tree, item)
                if os.path.isdir(itemPath):
                    if item == SVN:
                        self.delete_folder(itemPath)
                    else:
                        self.delete_svn_folder(itemPath)

if __name__ == '__main__':
    if Util.checkSystem() != WIN32:
        print 'Only supports the win32 os!'
        sys.exit()

    import win32api, win32con

    while(True):
        path = raw_input('please input the directory:')
        if Util.validatePath(path):
            svnDeleter = SVNDeleter()
            svnDeleter.delete_svn_folder(path)
            if svnDeleter.ifSuccess:
                print '\nSuccessful!'
                break
            else:
                print '********************** notice *************************'
                print '*  Some directory is in use, has not been deleted!!!  *'
                print '*******************************************************' 
        else:
            print '********************** notice ****************************'
            print '\'' + path + '\'', 'is not a valid directory!'
            print '**********************************************************'  
    raw_input()


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值