Home > Commands A-M > Commands Da-Dr

DELTREE


Description | Syntax | Parameters | Switches | Related | Notes | Examples | Errorlevels | Availability

Deletes a directory and all the files and subdirectories that are in it.


Syntax

DELTREE [/Y] [drive:]path [[drive:]path[...]]


Parameters
drive: (v6.0 Win95)
Specifies the drive where the directory you want to delete resides. You can specify more than one drive.
path (v6.0 Win95)
Specifies the name of the directory you want to delete. The DELTREE command will delete all the files contained in the directory you specify, as well as all subdirectories and files in the subdirectories subordinate to this directory. You can specify more than one directory.

Switches
/Y (v6.0 Win95)
Carries out the DELTREE command without first prompting you to confirm the deletion.

Related

For information about removing a directory, see the RMDIR command.
For information about deleting files, see the DEL command.


Notes
DELTREE and hidden, system, and read-only attributes

The DELTREE command deletes all files contained in a directory or subdirectory, regardless of attributes.


Using wildcards with DELTREE

You can use wildcards with the DELTREE command, but use them with extreme caution. If you specify a wildcard that matches both directory names and filenames, both the directories and files will be deleted. Before specifying wildcards with the DELTREE command, use the DIR command to view the files and directories you will delete.


Leaving an "empty" directory

If you specify the trailing slash with the directory name, the directory will be left empty. If you don't specify the trailing slash, the directory will also be deleted.


Examples

To delete the TEMP directory on drive C, including all files and subdirectories of the TEMP directory, type:

    DELTREE C:]\TEMP (MSDOS6.22) (WIN98)

Deletion in a directory

To delete all files and subdirectories of the TEMP directory on drive C, type:

    DELTREE C:]\TEMP\
    (MSDOS6.22) (WIN98)

    DELTREE C:]\TEMP\.
    (MSDOS6.22) (WIN98)

    DELTREE C:]\TEMP\*.*
    (MSDOS6.22) (WIN98)

    DELTREE C:]\TEMP\*
    (WIN98)

To delete (from TEMP directory on drive C) all those files and subdirectories that do have an extension TMP, type:

    DELTREE C:]\TEMP\*.TMP
    (MSDOS6.22) (WIN98)

To delete (from TEMP directory on drive C) only those files and subdirectories that don't have an extension, type:

    DELTREE C:]\TEMP\*.
    (MSDOS6.22) (WIN98)

    DELTREE C:]\TEMP\*
    (MSDOS6.22)

Notes: If you always give your filenames an extension but never give your subdirectory names an extension (which is the usual practice), then the above syntax can be used to delete ONLY subdirectories of TEMP but leave normal files.


All content AND named directory as well:

    DELTREE /Y C:]\TEMP > nul

All content but NOT the named directory:

    DELTREE /Y C:]\TEMP\ > nul

Subdirectories of named directory (without .EXTension):

    DELTREE /Y C:]\TEMP\*. > nul

All names whose extension are exact TMP:

    DELTREE /Y C:]\TEMP\*.TMP > nul

Errorlevels
Availability
External
DOS
v6.0 v6.10 v6.2 v6.21 v6.22 v6.23 v7.00 v7.0R1 v7.10 v8.00
Windows
Win95 Win98 WinME
Windows NT
none