tags:

views:

397

answers:

3

How would one go about deleting all subversion files from directory using Powershell?

+1  A: 

How about using SVN Export to get a clean checkout without .svn directories?

Edit

You might want to look at the answer here:

http://stackoverflow.com/questions/534798/command-line-to-delete-matching-files-and-directories-recursively

Sofahamster
Cannot do that, this is code that is from other machine, it's a mess.
epitka
+5  A: 

If you really do want to just delete the .svn directories, this could help:

gci c:\yourdirectory -include .svn -Recurse -Force | 
   Remove-Item -Recurse -Force

Edit: Added -Force param to gci to list hidden directories and shortened the code.

Keith is right that it you need to avoid deleting files with .svn extension, you should filter the items using ?.

stej
+3  A: 

Assuming you don't want to delete any files that might also have .svn extension:

Get-ChildItem $path -r *.svn -force | Where {$_.PSIsContainer} | 
    Remove-Item -r -force
Keith Hill
Yes, good catch :) However, I don't assume there is some file with this extension.
stej
Keith Hill
BTW I look forward to the day when you don't need `Where {$_.PSIsContainer}` and all you have to do is `gci . -r -containerOnly`. I have my Get-ChildItem proxied to work this way but I can't count on other folks having it. :-(
Keith Hill
Have you added a suggestion about `-containerOnly` to connect? I would vote for sure.
stej
I'd lose the wildcard on the pattern and just do ".svn" - otherwise you'll get folders that end with .svn
Duncan Smart
Stej, yes vote on it here: https://connect.microsoft.com/PowerShell/feedback/details/308796/add-enumeration-parameter-to-get-childitem-cmdlet-to-specify-container-non-container-both
Keith Hill
Ah, so the directories aren't named like foo.svn, they are literally called ".svn"? How about files? Are there files called just ".svn" or do they have names like "foo.svn"?
Keith Hill