Del (or Erase)

Index

Deletes named files. DEL and ERASE are synonymous.

Syntax:

To delete a file:
DEL [path] filename [/P]

To delete all files in a directory (with confirmation):
DEL path or
DEL path \*.*

To delete all files in a directory (without confirmation):
DEL path \?*.*
DEL path \** (in Dos7.0 - confirmation is required in Dos7.1)

filenameThe file to delete.
/PForces confirmation before deleting each file.

Notes:

  1. DEL only accepts one parameter specifying what is to be deleted - though this parameter can be written (using wildcards) so that multiple files are deleted. If more than one parameters is detected, the command aborts and an error message is displayed. DEL will interpreted a long-file-name-with-spaces as multiple parameters, causing an error. Enclosing the long-file-name-with-spaces in inverted commas solves the problem.

    
    D:\>del test 2.txt
    Too many parameters - 2.txt
    
    D:\>del "test 2.txt"
    
    D:\>_
     

  2. DEL will not delete files that have "read-only", "hidden", and/or "system" attributes set. To delete such files, one can use DELTREE or modify the necessary attributes with ATTRIB.

  3. Using either DEL path \*.* or DEL path will delete all files in a directory, but both forms first give a warning that all files in the directory will be deleted and ask for confirmation before proceeding. To avoid this message and the request for confirmation (which can be trying in batch files) there are a number of alternatives:
    • DEL [path] \?*.*
    • DEL [path] \** (in Dos7.0 - confirmation required in Dos7.1)
    • ECHO Y | DEL [path] \*.*
    • DELTREE /Y [path] \*.*

  4. On the other hand, to require confirmation before each file in a group is deleted, use:

  5. There is no easy way to delete a specific file or group of files from all branches of a directory. Although a list of such files is easy to obtain (using DIR /S filespec), it has been found extraordinarily difficult to persuade DEL to use such a list to delete these files. In a series of newsgroup postings sparked by Ray Woodcock1, the general consensus was that such an operation was best left to a third-party utility (SWEEP - an old PC Magazine utility was mentioned).

References

Ref.#FromTitleNewsgroupDate
1Ray WoodcockPipes and Redirects for DELalt.msdos.batch 15 Feb 2000

File Details:

Internal


If you should have any comments or suggestions,
please contact: Bob Watson
.
This page last revised:
June 5, 2000.