Al Fasoldt's reviews and commentaries, continuously available online since 1983

DELTREE's hidden power

By Al Fasoldt
Copyright © 1998, Al Fasoldt

    DELTREE has been around a while, and it's known by many users as a quick DOS command that gets rid of entire directories -- whole folders, in Windows parlance. Unlike the Explorer shell built into Windows, DELTREE doesn't bother with such niceties as honoring read-only status for files and subfolders inside the folder you want to delete; it just zaps the entire thing.
   The standard DELTREE command syntax looks like this:
   deltree foldername

   And it's often seen in this form, which tells DELTREE not to get confirmation:
   deltree /y foldername

   But DELTREE is more powerful and far more flexible than this simple command syntax suggests. DELTREE works with multiple parameters, meaning it can delete more than one folder (in separate locations) at a time. It also can delete files instead of or in addition to folders. And it knows how to understand wildcards for both filenames and folder names.
   Let's take a look at how these added functions work.
   Suppose you have three folders in the root of your C: drive that you want to delete. This command gets rid of them in one step:
   deltree /y folder1 folder2 folder3

   If you were smart and named all of them so that the first four letters are TEMP, you can delete all of them this way:
   deltree /y temp*

   You can expand the reach of DELTREE this way:
   deltree /y c:\temp* d:\temp* d:\download\temp*

   The way DELTREE can delete files as well as folders solves a long-standing flaw in the DEL command. DEL can delete only one fully specified file at a time (as in DEL MYFILE.TXT). It can delete many files at the same time, but only using wildcards (as in DEL *.TXT). It cannot work with more than one parameter, meaning you can't delete all .TXT files and all .DOC files with one command.
   But DELTREE can do this easily. Let's say you want to get rid of all old texts in a folder. They're named in this kind of pattern: MYJAN.TXT, MYFEB.FIL, MYMAR.DOC, OLDAPR.TXT and OTHRMAY.BAK. The DEL command won't let you zap all those files at once, but DELTREE will:
   deltree /y my*.* old*.* *.bak

   Note that spaces are used as separators. You can use as many parameters as can fit into the DOS command-line environment. (Microsoft gives varying numbers for this. Just try out some long commands and see if they work.)
   Two warnings:
   Using wildcards with DELTREE can be very dangerous. Be careful.
   Yes, you can delete every file on your hard drive with a stupid command such as DELTREE C:\. Don't even think of it.