Command line tool to delete folder with a specified name recursively in Windows?

瘦欲@ 提交于 2019-11-27 02:47:30

Similar to BlackTigerX's "for", I was going to suggest

for /d /r . %d in (_svn) do @if exist "%d" rd /s/q "%d"

Cédric Rup

Time to learn some PowerShell ;o)

Get-ChildItem -path c:\projet -Include '_svn' -Recurse -force | Remove-Item -force -Recurse

The first part finds each _svn folder recursively. Force is used to find hidden folders. Second part is used to delete these folders and their contents. Remove commandlet comes with a handy "whatif" parameter which allows to preview what will be done.

PowerShell is available for Windows XP and Windows Vista. It is present on Windows 7 and on Windows Server 2008 R2 by default.

It's a MS product, it's free, and it rocks!

Rajesh Gautam PhD

For inclusion/invocation from within a BATCH file use (say for removing Debug and Release folder):

for /d /r . %%d in (Debug Release) do @if exist "%%d" echo "%%d" && rd /s/q "%%d"

double % are required within a batch file to work as escape chars. Else it reports error of syntax.

Thanks.

BlackTigerX
for /f "usebackq" %d in (`"dir _svn /ad/b/s"`) do rd /s/q "%d"

http://ebersys.blogspot.com/2008/07/recursively-delete-svn-folders-easy-way.html

In Windows? If you are using tortoiseSVN you can use the export command to export a copy of the project without the .svn/_svn folders.

Zhu Tao
import os
import shutil

curdir = os.path.abspath(os.path.dirname(__file__))

def removedir(dirname, name = ".svn"):
    if os.path.isdir(dirname):
        for file in os.listdir(dirname):
            if os.path.isdir(os.path.join(dirname, file)) and file == name:
                thedir = os.path.join(dirname, name)
                shutil.rmtree(thedir)
                print ".",
            else:
                removedir(os.path.join(dirname, file))

I think you can try this Python script, which will work under any OS if you've got Python installed.

Another option from SVN Forum: use XCopy with a file that contains the list of files/directories to be excluded (.svn or _svn in this case)

XCopy C:\VersionedFolder C:\UnVersionedFolder /EXCLUDE:C:\No.SVN.txt /E /C /I /F /R /Y

Here... with FreeCommander or TotalCommander

http://www.broobles.com/blog/posts/36

socendani

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!