79

I want to delete every "_svn" in every folder and subfolder...

For example

c:\
  proyect1
   _svn
   images
     _svn
     banner
       _svn
     buttons
       _svn

Then I run something like

rm-recurse c:\proyect1 _svn

And I should get:

c:\
  proyect1
   images
     banner
     buttons

The ideal thing would be a tiny stand-alone EXE or something like that.

-- Thanks Grant, as soon as I posted the question I saw SVN documentation about the SVN export command, but I also want to delete the _vti_* folders stuff Visual Studio creates, so I'll also explore the for solution.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
opensas
  • 60,462
  • 79
  • 252
  • 386
  • Please reword this in the form of a question; are you asking for help in developing a tool to do this, or do you wish to know if any such tools are available? – Rob Feb 06 '09 at 17:53
  • 14
    .bat files don't solve all Windows problems. Sometimes you have to fill them with commands and stuff first. – Grant Feb 06 '09 at 17:57

8 Answers8

150

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

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

JMD
  • 7,331
  • 3
  • 29
  • 39
  • 3
    Yes, because the nature of this "for" is that it adds "_svn" to every directory entry as it recurses the directory tree. – JMD Feb 06 '09 at 18:18
  • Your solution bypasses that by returning an explicit list of the existing directories. – JMD Feb 06 '09 at 18:19
  • 1
    Though this is older than 2 years old, you taught me something new! Thanks. – Ryan Ternier Oct 27 '11 at 18:32
  • @JMD If I wanted to target D:\Projects\ from a BAT FILE, how would you place a specific dir path into this command? – Ravi Ram Dec 13 '13 at 14:17
  • 5
    @DavidKEgghead, just replace the '.' (current directory) with the directory you want to search. Be sure to wrap it in quotes if your target contains spaces. Thus, you would use: `for /d /r "D:\Projects" %d in (_svn) do @if exist "%d" rd /s/q "%d"` I often test these by replacing the actual 'work' with an echo first: `for /d /r "D:\Projects" %d in (_svn) do @if exist "%d" echo "%d"` so that I can see what things I'm going to affect. – JMD Dec 13 '13 at 17:30
  • 3
    When I run this recursively sometimes I get "the-directory-is-not-empty" Why so? What might the reason behind that? – SabareeshSS Aug 20 '15 at 11:14
  • 7
    If you want to save this to a bat file, don't forget to replace % by %%. – Jesper Mygind Nov 04 '16 at 07:50
  • 1
    @JMD +1 for the answer. A good use case is recursive deletion of `__MACOSX` directories and `.DS_Store` files, if you have copied files from Mac OS to Windows OS. Save following lines to `del.bat` file and double click to run it. `del /f /s .DS_Store for /d /r . %%d in (__MACOSX) do (@if exist "%%d" rd /s /q "%%d")` – Hamza Rashid Mar 27 '18 at 11:13
  • what if the specific folder name contains space, for example `My Folder` instead of `_svn`? i tried escaping it within quotation marks but it dosen't work! – S.Serpooshan Jul 15 '23 at 06:59
41

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!

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Cédric Rup
  • 15,468
  • 3
  • 39
  • 30
26

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.

Adriano Carneiro
  • 57,693
  • 12
  • 90
  • 123
15
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

Adriano Carneiro
  • 57,693
  • 12
  • 90
  • 123
BlackTigerX
  • 6,006
  • 7
  • 38
  • 48
  • I get an error: couldn't find dir file, I tried with cmd.exe /c dir ..., but i get the same error, however, JMD's solution dis the trick... – opensas Feb 06 '09 at 20:28
  • Oops, I checked the page you linked to, seems like there where a couple of ´´ (single quotes) missing... fixing that also did the trick... – opensas Feb 06 '09 at 20:32
10

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.

Grant
  • 11,799
  • 13
  • 42
  • 47
  • 1
    You can also do svn export with the command line tool whether you are on Windows or not. – Parappa Feb 06 '09 at 18:11
  • I think the reason people end up needing to recursively delete the .svn/_svn folders is because they've directly copied their local working copy to a new location in order to do a folder comparison of their modified version compared to a clean export, i.e. after something goes awry with the modified local working copy. (At least that's why I've needed it. It's definitely easier/faster to just use 'svn export' when that's possible.) – JMD Mar 29 '12 at 17:44
4
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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Zhu Tao
  • 7,581
  • 9
  • 35
  • 38
3

Here... with FreeCommander or TotalCommander

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

socendani

  • 1
    As a long time TotalCommander (formerly Windows Commander!) user, I can't let this answer stay negative. This is a great, simple solution for someone who already has TC installed. I'm glad to have learned this nifty trick. Thanks! – Adam Tuttle Jan 13 '10 at 20:25
  • 1
    The most straight forward solution here! – Amio.io Jul 16 '14 at 09:11
3

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
Teorist
  • 86
  • 8