posts - 431,  comments - 344,  trackbacks - 0
D:/ DeleteSVN.py  文件

#coding=utf-8
import os
import shutil
import sys
import stat

def deleteSubFile(svnpath):
    names = os.listdir(svnpath)
    for name in names:
       
        fp = os.path.join( svnpath, name)
        if (os.path.isfile(fp)):
            os.chmod( fp, stat.S_IWRITE)
            os.remove(fp)
        else:
            deleteSubFile(fp)
            

def deleteSVN(parentPath = None, dir = None):
    if (dir != None and dir == '.svn'):
        deleteSubFile(os.path.join( parentPath, dir))
        shutil.rmtree(os.path.join( parentPath, dir), True, False)
        print 'deleted ', os.path.join( parentPath, dir)
    else:
        if (dir != None):
            filePath = os.path.join( parentPath, dir)
        else:
            filePath = parentPath
        names = os.listdir(filePath)
        for name in names:
            fp = os.path.join( filePath, name)
            if (os.path.isdir(fp)):
                deleteSVN(filePath, name)


if len(sys.argv) < 2:
    print 'Usage: python % <file path>' % os.path.basename(sys.argv[0])
    sys.exit(-1)

if os.path.isfile(sys.argv[1]):
    print '请选择文件夹, 而不是文件'
else:
    deleteSVN(parentPath = sys.argv[1])



bat文件代码如下:
python D:/DeleteSVN.py "%1"
@pause

这样把包含svn文件的文件夹直接拉到bat文件中, 就会删除掉里面所有svn文件
posted on 2009-06-12 23:19 周锐 阅读(383) 评论(0)  编辑  收藏 所属分类: Python

只有注册用户登录后才能发表评论。


网站导航: