码迷,mamicode.com
首页 > 其他好文 > 详细

一次性删除 .svn 文件夹

时间:2020-01-07 01:14:31      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:sdn   python   import   mail   iss   use   path   http   dir   

方法一 (Windows 7; Python 3.5.2)

import os

for (p,d,f) in os.walk(r"G:\qycache\test"):
     if p.find('.svn')>0:
         os.popen('rd /s /q %s'%p)

方法二(Windows 7; Python 3.5.2)

#! /windows

'''
     File    : CodeLine.py
     Author  : HCLAC
     E-Mail  : hclac@sina.com
'''

import os,sys
import stat

absolutPath = os.getcwd()

def DeleteSvnDir(delDirName):

    if os.path.isfile(delDirName):
        try :
            #print (delDirName)
            os.chmod(delDirName, stat.S_IWRITE )
            os.remove(delDirName)
        except:
            pass
    elif os.path.isdir(delDirName):
        for item in os.listdir(delDirName):
            itemsrc = os.path.join(delDirName, item)
            DeleteSvnDir(itemsrc)
        try:
            os.rmdir(delDirName)
            #print (delDirName)
        except:
            #print (delDirName)
            pass       

def FindSvnDir(OrginPath):

     for root, dirs, fileNames in os.walk(OrginPath):

        for dirName in dirs:
            if dirName == ".svn":
                  delDirNameTemp = os.path.join(absolutPath, root)
                  delDirName = os.path.join(delDirNameTemp, dirName)
                  #print (delDirName)
                  DeleteSvnDir(delDirName)
            #else :
                #FindSvnDir(dirName)
#main
FindSvnDir(absolutPath)

方法三(Windows 7; cmd.exe)

@echo On
@Rem delete .svn folders
@Rem PROMPT [Com]

@for /r . %%a in (.) do @if exist "%%a/.svn" rd /s /q "%%a/.svn"
@Rem for /r . %%a in (.) do @if exist "%%a/.svn" @echo "%%a/.svn"

@echo Mission Completed.
@pause

参考资料:
https://blog.csdn.net/weixin_34019929/article/details/93316753
https://blog.csdn.net/aa779025105/article/details/50791227
https://blog.csdn.net/zltAlma/article/details/88739022

一次性删除 .svn 文件夹

标签:sdn   python   import   mail   iss   use   path   http   dir   

原文地址:https://www.cnblogs.com/chenjo/p/12159180.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!