Python递归删除.svn文件夹
来源:互联网 发布:c语言二叉查找树 编辑:程序博客网 时间:2024/05/01 19:40
import os, stat; root_dir = r'X:\XXX\XXX';def walk(path): for item in os.listdir(path): subpath = os.path.join(path, item); mode = os.stat(subpath)[stat.ST_MODE]; if stat.S_ISDIR(mode): if item==".svn": print "Clean %s ..." % subpath; print "%d deleted!" % purge(subpath); else: walk(subpath);def purge(path): count = 0; for item in os.listdir(path): subpath = os.path.join(path, item); mode = os.stat(subpath)[stat.ST_MODE]; if stat.S_ISDIR(mode): count += purge(subpath); else: os.chmod(subpath, stat.S_IREAD|stat.S_IWRITE); os.unlink(subpath); count += 1; os.rmdir(path); count += 1; return count; if __name__=='__main__': walk(root_dir);
借鉴以上代码转自:
http://onlypython.group.javaeye.com/group/blog/53926
import os, stat; root_dir = r'X:\XX\XX';def purge(path): count = 0; for item in os.listdir(path): subpath = os.path.join(path, item); mode = os.stat(subpath)[stat.ST_MODE]; if stat.S_ISDIR(mode): count += purge(subpath); else: os.chmod(subpath, stat.S_IREAD|stat.S_IWRITE); os.unlink(subpath); count += 1; os.rmdir(path); count += 1; return count;def callback(arg, directory, files): if os.path.split(directory)[1]=='.svn': print directory; #使用os.removedirs()删不掉 print "Folder [%s](%d files) deleted." % (directory, purge(directory)); print '--------------------'; if __name__=='__main__': print 'start'; os.path.walk(root_dir, callback, 0); print 'complete.';
http://www.cnblogs.com/jaypei/archive/2008/05/08/1188764.html
第一种方法每次需要修改文件夹路径,进行了些修改
#!/usr/bin/python # -*- coding: utf8 -*- import sys, os, statdef walk(path): for item in os.listdir(path): subpath=os.path.join(path, item) mode=os.stat(subpath)[stat.ST_MODE] if stat.S_ISDIR(mode): if item==".svn": print "Cleaning %s ..." % subpath print "%d deleted" % purge(subpath) else: walk(subpath) def purge(path): count=0 for item in os.listdir(path): subpath=os.path.join(path, item) mode=os.stat(subpath)[stat.ST_MODE] if stat.S_ISDIR(mode): count+=purge(subpath) else: os.chmod(subpath, stat.S_IREAD|stat.S_IWRITE) os.unlink(subpath) count+=1 os.rmdir(path) count+=1 return count if len(sys.argv)!=2: print "Usage: python SVNClean.py path" sys.exit(1) walk(sys.argv[1])
http://www.cnblogs.com/allenblogs/archive/2010/09/14/1826005.html
方法三:
#coding=utf-8import osimport shutilimport sysimport statdef 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])
4行python代码,删除svn文件夹
import osfor (p,d,f) in os.walk("要删除的目录路径"): if p.find('.svn')>0: os.popen('rd /s /q %s'%p)
http://www.cnblogs.com/alexander-lee/archive/2010/02/23/1671905.html
- Python递归删除.svn文件夹
- 【SVN】递归删除.svn文件夹
- 递归调用删除项目中的svn文件夹
- PHP递归批量删除.svn文件夹
- 递归删除.svn文件夹以及文件
- 删除某一文件夹下面所有.svn文件夹(递归地)
- 递归删除Windows某一文件夹下的 .svn文件夹
- python实现递归删除空文件夹
- python 实现递归删除文件和文件夹
- 递归删除指定目录下的.svn文件夹
- 递归 删除文件夹
- 递归删除文件夹
- php递归删除文件夹
- Java删除文件夹--递归
- vc递归删除文件夹
- 递归删除文件夹
- java递归删除文件夹
- Java递归删除文件夹
- 当最后一块残铁被捡走后,一切又像回到了从前...
- Oracle监听自动关闭问题 -- 由于修改了计算机名称,导致出现这个错误
- 《大话处理器连载》 PC机结构探秘(5) 输入设备——五觉
- No configuration found for the specified action: 'xxx/xxx.action' in namespace: ''. Form action def
- 正则表达式大全
- Python递归删除.svn文件夹
- 删除数组中一样的元素
- linux下echo命令详解
- Nucleus学习
- Python多线程 简明例子
- Boost学习系列4-事件处理(上)
- Makefile,Linux程序员你伤不起
- vc自定义消息的发送与接收的方法实现
- 超频