您的位置:首页 > 编程语言 > Python开发

一段删除.svn目录的python脚本

2014-02-10 15:38 288 查看

代码如下:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import shutil

# call the delete_svn function
def delete_svn(root_dir):
subdir_list = os.listdir(root_dir)
for name in subdir_list:
to_delete_name = os.path.join(root_dir, name)
if name == '.svn':
shutil.rmtree(to_delete_name, ignore_errors=None)
print 'deleting the ' + to_delete_name
continue
if os.path.isdir(to_delete_name):
delete_svn(to_delete_name)

# check the length of params
if len(sys.argv) < 2:
print 'Please specify the dir path'
sys.exit()

# check if the input dir path is valid
root_dir = sys.argv[1]
if not os.path.exists(root_dir):
print 'Pleanse specify an existing path'
sys.exit()

# check if the input dir path is a directory
if not os.path.isdir(root_dir):
print 'Please specify an directory path'
sys.exit()

delete_svn(root_dir)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: