How can I recursively delete folder with a specific name with PowerShell?
-
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.
-
Answer:
This http://www.tigraine.at/2009/11/24/removing-svn-folders-with-powershell/ should do it: get-childitem -Include .svn -Recurse -force | Remove-Item -Force —Recurse http://www.vistax64.com/powershell/80403-pecursive-delete-implementation-powershell.html 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 } }
Tone at Stack Overflow Visit the source
Other answers
I tend to avoid the -Include parameter on Get-ChildItem it is slower than -Filter. This is what I would use: get-childitem . -include .svn,_svn -recurse -force | remove-item -recurse -force or if typing this at the prompt: ls . -inc .svn,_svn -r -fo | ri -r -fo
Keith Hill
Related Q & A:
- How can I force the login to a specific ip address?Best solution by Stack Overflow
- Can I scroll ScrollView programmatically to a specific position?Best solution by Stack Overflow
- How can I lower the resolution on a video I recorded?Best solution by Yahoo! Answers
- How can I play my PS3 using a laptop as a monitor?Best solution by Yahoo! Answers
- How can I permanently delete my yahoo account?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.