views:

107

answers:

2

I can delete files with specific extensions in multiple folders with this:

Get-childitem * -include *.scc -recurse | remove-item

But I also need to delete folders with a specific name - in particular those that subversion creates (".svn" or "_svn") when you pull down files from a subversion repo.

+2  A: 

This one should do it:

get-childitem -Include .svn -Recurse -force | Remove-Item -Force –Recurse

Other version:

$fso = New-Object -com "Scripting.FileSystemObject"
$folder = $fso.GetFolder("C:\Test\")

foreach ($subfolder in $folder.SubFolders)
{
    If ($subfolder.Name -like "*.svn")
    {
        remove-item $subfolder.Path -Verbose
    }       
}
Leniel Macaferi
perfect - thanks!
Tone
+1  A: 

I tend to avoid the -Include parameter on Get-ChildItem it is slower than -Filter. This is what I would use:

get-childitem . -recurse ?svn -force | remove-item -recure -force

or if typing this at the prompt:

ls . ?svn -r -fo | ri -r -fo
Keith Hill