Windows XP doesn’t include my old standby “deltree,” and there is no combination of options that “del” can take to delete hidden directories recursively (yeah, I’m talkin bout you, .svn directories!)
After some rooting around the web and two tablespoons of experimentation, I’ve finally come up with the following Windows Powershell command that can recurisvely delete hidden directories and their contents:
get-childitem . -include .svn -force -recurse | foreach ($_) {remove-item -force $_.fullname}
The first “.” after the get-childitem is the base directory you want to start in. The parameter after “-include” is the pattern you want to operate on. In my case, the wretched Subversion directories (.svn)
Unfortunately, this script still prompts me for each directory I want to delete, but that’s only a tweak or two away from perfection.
Thanks, this came in quite handy deleting a bunch of .svn directories. To make it not prompt you for each one, simply add the -recurse command right after remove-item. Here is the modified command:
get-childitem . -include .svn -force -recurse | foreach ($_) {remove-item -recurse -force $_.fullname}
Thanks Tony!
Follow up note: For the case of .svn directories, I later learned about the Subversion “Export” command, which can create a SVN file hierarchy without it being versioned in the first place.
Hey Bill
Actually you don’t need to use foreach-object, you can pipe directly do remove-item. You can also replace -include with -filter, it performs faster.
get-childitem . -filter .svn -force -recurse | remove-item -recurse -force
thanks guys
saved me hours
and my hair
Thanks this was really helpful ! exactly what I was trying to do !
You are kidding me???!!! What are these guys (not you, but Microsoft) thinking?
I was just looking for the equivalent of “rm -rf”, and had no idea I would encounter this!
Still, nice work, and thanks.
How about navigating to the dir containing the files/dirs you want to remove and using…
del /s /q *.*
Note the /q bit means you wont get prompted to confirm deletion