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:
- Copy the code below and paste it into your favorite text editor.
- Save the file as whatever-you-want.reg (the .reg is the important part).
- Double-click the .reg file you just created.
- 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. ![]()
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.
Subscribe6 Comments on Deleting .svn Folders