从CVS库中迁出项目以后,在目录中含有CVS目录。通过python进行递归删除。
由于PYTHON中貌似不能直接删除非空目录,所以先将CVS目录下的文件删除,再删除CVS目录。
采用walk方法,递归遍历各目录。
来源:http://blog.csdn.net/moxuansheng/article/details/6450687
'''
Created on 2011-5-27
@author: Administrator
'''
#coding=utf-8
import os
import shutil
dir = "G://tmp//sz//ngtsverify"
def removeDir():
for root, dirs, files in os.walk(dir, True, None, False):
if 'CVS' in root:
print("the root is: ", root)
files = os.listdir(root)
for f in files:
if (os.path.isfile(os.path.join(root,f)) == True):
print('the file name is:', os.path.splitext(os.path.join(root,f))[0])
#删除文件
os.remove(os.path.join(root,f))
#删除主目录
os.removedirs(root)
if __name__ == '__main__':
removeDir()
