June 18, 2009

Remove SVN folder using Powershell

I use subversion as my source code repository and it generates a svn folder. There are times where I would just like to remove all svn folders and files attached to this. Here is a simple one liner in powershell to do just that:
gci 'C:\_DevCode\CustomApps' -include _svn -recurse -force | foreach ($_) { del $_.fullname -recurse -force -whatif}
Three things:
  1. -whatif will do the simulation, so please remove when you are reay to run
  2. My folders for svn were setup as _svn while the default is actually .svn, so you may need to modify that
  3. -force will make sure to get rid of hidden files
You can also use this same code for example to search your machine and get rid of thumbs.db!
gci 'C:\' -include thumbs.db -recurse -force | foreach ($_) { del $_.fullname -recurse -force -whatif}

3 comments:

  1. Joe,

    Nice trick..

    Can I ask why you didn't just use pipe the folders to Remove-Item?

    Like..
    Get-ChildItem 'C:\_DevCode\CustomApps' -include _svn -recurse -force | Remove-Item -Recurse -Force

    ReplyDelete
  2. And I forgot the -whatif on the end as well.. :)

    ReplyDelete
  3. Actually, your approach is much nicer! Thanks Steve!

    ReplyDelete