Home > Technology > Delete DOS Directories Recursively

Delete DOS Directories Recursively

January 23rd, 2008

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.

Bill Technology

  1. Tony
    April 22nd, 2008 at 03:10 | #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. October 1st, 2008 at 17:27 | #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. August 13th, 2009 at 11:51 | #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. toy
    October 12th, 2010 at 11:52 | #4

    thanks guys
    saved me hours
    and my hair

  5. steve
    April 4th, 2011 at 16:31 | #5

    Thanks this was really helpful ! exactly what I was trying to do !

  6. Stephen
    May 20th, 2011 at 19:04 | #6

    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.

  1. No trackbacks yet.