#coding=gbk
#FileName:delspldir.py
#delete special directory
#将当前目录及子目录中的.svn文件夹删除
import
os
import
stat
def
delDirFile(dirName):
'''删除指定目录中的全部内容'''
if
os.path.isfile(dirName):
os.chmod(dirName, stat.S_IWRITE)
os.remove(dirName)
else
:
dirList
=
os.listdir(dirName)
if
dirList
=
=
[]:
os.rmdir(dirName)
else
:
#dirName非空
print
dirName,
'非空'
for
curDir
in
dirList:
delDirFile(os.path.join(dirName,curDir))
os.rmdir(dirName)
print
'delete %s successfully!'
%
dirName
def
delSplDir(rootDir,dirName):
'''从当前目录开始,递归删除目录及子目录中的
所有文件夹名为dirName的文件夹
'''
if
os.path.basename(rootDir)
=
=
dirName:
delDirFile(rootDir)
else
:
dirList
=
os.listdir(rootDir)
for
everyDir
in
dirList:
curDir
=
os.path.join(rootDir,everyDir)
if
os.path.isdir(curDir):
if
os.path.basename(curDir)
=
=
dirName:
delDirFile(curDir)
else
:
delSplDir(curDir,dirName)
delSplDir(os.getcwd(),
'.svn'
)