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
周銳 閱讀(391)
評論(0) 編輯 收藏 所屬分類:
Python