I’ve been doing a spot of work that requires version control, so we’ve been using Subversion. It’s great, but if you’re anal like me then you may not like the .svn files that litter your working directories after you’re finished. Rather than doing a full SVN export, I cobbled together a VB script to delete them all in one fell swoop. Might help someone else on a random Google search. so posting it here. Sorry for being boring.


OPTION EXPLICIT
Dim FSO, Folder, SubFolder, LogFile, DeletedCount
DeletedCount = 0
If MsgBox ("This will delete ALL of your subversion folders for this repository. Are you sure?", vbYesNo) = vbYes Then
Set FSO = CreateObject("Scripting.FileSystemObject")
Set LogFile = FSO.CreateTextFile("./svn-cleanup.txt")
DoSvnDelete ("./")
MsgBox(DeletedCount & " .svn file(s) were deleted. See log file for rundown.")
Set FSO = Nothing
End If
Sub DoSVNDelete (Path)
If FSO.FolderExists (Path) Then
Set Folder = FSO.GetFolder(Path)
If Folder.SubFolders.Count > 0 Then
For Each SubFolder In Folder.SubFolders
If SubFolder.Name = ".svn" Then
LogFile.WriteLine ("Deleted: " & Path & "\" & SubFolder.Name)
SubFolder.Delete
DeletedCount = DeletedCount + 1
Else
DoSVNDelete (SubFolder)
End If
Next
End If
End If
End Sub

Download the VBS file here.

13 Responses to “Recursively Delete Subversion Folders”

  1. chris Says:

    worst post EVER!

  2. jof Says:

    what has happened to this blog?

  3. Dave Says:

    Sorry :(

    Glad it got the title of worst post ever, though. Quite an accolade!

    I’ll try better next time.

    I rate this post an F-

    FAIL

  4. Hannah Says:

    aaaaaaaghhhhhhhhhhhhhh

    my boyfriend is a geek….i just noticed….

  5. Dave Says:

    Yeah, well it could be worse. At least I’m not into physics and stuff.

  6. Colin Says:

    ” Dave Says:
    May 18th, 2007 at 12:06 pm

    Yeah, well it could be worse. At least I’m not into physics and stuff.”

    Does Necrophilia and Animal Fettling come under “stuff”? ‘cos you’re well into that!

  7. Colin Says:

    You know, this was such a bad post, that when my mum walked into the room and asked her what I was looking at, I couldn’t tell her the truth so I said, “Hardcore Porn”

  8. Dave Says:

    I thought I saw your name on a loaf of bread…. you know the deal :D

  9. Google searcher Says:

    Dear Mr Dave,

    I was perusing google for such a help, those pesky sfv files infiltrate all my directories, sometimes with disasterous consequences, one of them even crept out of my usb port thru my USB cup warmer and spoiled my coffee the little rascal, thankyou for taking the time to help another fellow coder delete the sneaky bastards en-masse, now if only I could write a program to delete all my .exe files in one go that crazy windows program might not act up so much.

    thanks again

    Geeky T Geekerton, geeksville!

  10. Google searcher Says:

    did I say sfv files, damn it!!!

  11. Dave Says:

    Cheeky sod.

  12. Dave Says:

    …and Lee, post something or some photos damn it!

  13. azizasm Says:

    The easiest way is by creating a .cmd script file at the root directory and execute it. Here is the code for cleanSVN.cmd :

    for /f “tokens=* delims=” %%i in (‘dir /s /b /a:d *svn’) do (
    rd /s /q “%%i”
    )

    regards,
    azizasm (Malaysia)

Leave a Reply