How can I recursively delete folder with a specific name with PowerShell?

Viewed 31182

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.

3 Answers

For fast deletion, use -Filter

To recursively delete a folder with a specific name -Filter is significantly faster than -Include.

So, for visibility, here is the faster version of @Keith's answer:

Fully typed-out:

Get-ChildItem -Filter .svn -Recurse -Force | Remove-Item -Recurse -Force

Short version:

ls . -filter .svn -r -fo | ri -r -fo
Related