Deleting .svn Folders

From time to time, I find myself looking at a directory full of .svn folders that I need to delete for one reason or another. On the Mac it’s not really a problem. I’m reasonably well-versed in the art of the Shell, so it was a trivial matter to pass the results of a find through to rm:

rm -rf `find . -type d -name .svn`

On Windows, though, I’m not so well-versed. DOS isn’t the easiest beast to tame and I (quite intentionally) haven’t written a batch script in years. As an avid Cygwin user, I can just crack open a shell and use the syntax above, but I’m also a user of TortoiseSVN and tend to spend more time in Windows Explorer than I do in Cygwin. As such, I found the idea of having a Windows Explorer context menu option appealing. A little hunting and pecking turned up a bit of code that, with a little modification, does exactly what I need it to do.

For anyone that may also be interested:

  1. Copy the code below and paste it into your favorite text editor.
  2. Save the file as whatever-you-want.reg (the .reg is the important part).
  3. Double-click the .reg file you just created.
  4. Confirm that you want to update your registry.

It goes without saying, of course, that all of the usual registry backup admonitions apply here. Monkeying about in the registry can be dangerous.

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\DeleteSVN]
@="Delete SVN Folders"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\DeleteSVN\command]
@="cmd.exe /c \"TITLE Removing SVN Folders in %1 && COLOR 9A && 
FOR /r \"%1\" %%f IN (.svn) DO RD /s /q \"%%f\" \""

Update 2/20/2008: When I published this, I neglected to include a screenshot to provide some visualization of how the context menu option is presented. A few folks have asked for it, so the image shown below is a cropped image highlighting the relevant section. For a complete look at my context menu, click the image. Windows Explorer context menu snippet

Notes:

  • The last line should be edited to be on a single line. It was split for legibility.
  • I’m running Windows XP. The first line may need to be changed for other Windows versions.

For what it’s worth, the OS X solution above can easily be adapted to a Finder context menu by employing Automator. I don’t spend much time in Finder so I haven’t bothered, but I have a number of other scripts that I’ve added to the Finder context menu.

Subscribe9 Comments on Deleting .svn Folders

  1. GrahamW said...

    Perhaps you thought of this already — but how about just use Windows Explorer search function (right-click on a folder) to search for *.svn. That’ll give you a list, and it’s recursive, and it can be filtered for date. You can then select all or some from the list, and delete.

  2. Rob Wilkerson said...

    True. Maybe it’s the geek in me, but that solution just felt clunky and uninspired. This direction seems infinitely more elegant…doesn’t it? :-D The truth is, I’ve never felt very comfortable with Windows search functionality, so it may just be a trust issue.

  3. GrahamW said...

    I personally don’t think much of search-in-file capability, but have had years of faithful service from the search-by-filename functionality, and often use it for exactly this kind of purpose with no trouble. What I really like is the ability to see the list of files before deleting, (like by date) and sort them in various ways to be really sure there’s nothing there I should keep. Regardless, your technique is cool too, if this is a very predictable scenario with no doubt about the outcome.

  4. Rob Wilkerson said...

    Yeah, I agree – the key is predictability. Deleting anything is scary if that component is lost. :-)

  5. Lisbeth said...

    Lovely – even better than what I was looking for! (And as far as I can tell, it has only deleted what it should).

  6. Mehdi said...

    Nice post. I am quite new to subversion and did not even know there is a hidden svn folder there ;-)

    It helped a lot.
    Thanks

  7. Aw Guo said...

    It’s really useful! Thanks :)

  8. Ken De Volder said...

    Doesn’t seem to work in Vista.. any tips?

  9. Rob Wilkerson said...

    I have to admit that I’ve never even laid hands on Vista. My only thought would be the Registry Editor version at the top of the regedit script. I suspect it’s incremented since XP.