Delete DOS Directories Recursively

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.

7 Replies to “Delete DOS Directories Recursively”

  1. 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}

  2. 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.

  3. 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

  4. 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.

  5. 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

Leave a Reply to Bill Cancel reply

Your email address will not be published. Required fields are marked *