DEL – Windows CMD Command

Delete one or more files

If a folder name is given instead of a file, all files in the folder will be deleted, but the folder itself will not be removed.

Error levels: DEL will return an Errorlevel of 0, irrespective of the delete succeeds, or fails for any reason.
(If you delete files using PowerShell then a True/False return code ($?) will be set correctly.)


If the files were successfully deleted %ERRORLEVEL% = 0
Bad or no parameters given %ERRORLEVEL% = 1

Undeletable Files

Files are sometimes created with a very long filename or a trailing period or with reserved names (CON, AUX, COM1, COM2, COM3, COM4, LPT1, LPT2, LPT3, PRN, NUL) and as a result, they become impossible to delete with Windows Explorer.

To delete such files use the syntax: DEL “\\?\path to file”
You can also use “\\.\path to device”

Alternatively for long filenames, you can reduce the total path length by using SUBST to map a drive letter to the folder containing the file.

It is also possible to delete long paths using RoboCopy – Copy/Move the required files to a temporary folder and then delete the folder, one gotcha with that technique is RoboCopy’s tendency to follow symbolic links which can cause files outside the source folder to be moved/ deleted.

If a file is still ‘undeletable’ this may be caused by the indexing service, temporarily stop the service and then delete the file.

Permanent deletion

Deleting a file will not prevent third-party utilities from un-deleting it again. Secure file deletion utilities are available, however for casual use, you can turn any file into a zero-byte file to destroy the file allocation chain like this:

TYPE nul > C:\examples\MyFile.txt
DEL C:\examples\MyFile.txt

Delete Locked files

Typically this is caused by the Offline Cache or Internet Explorer temp files.

Close all applications
Open a command prompt
Click Start, and then Shut Down
Simultaneously press CTRL+SHIFT+ALT.
While you keep these keys pressed, click Cancel in the Shut Down Windows dialog box.
In the command prompt window, navigate to the cache location, and delete all files from the folder (DEL /s)
At the command prompt, type explorer, and then press ENTER.

DELTREE – Older versions of Windows had the DELTREE command to delete all files and subfolders. This can be replicated with a script as shown on the DELTREE page.

Normally DEL will display a list of the files deleted, If Command Extensions are disabled; it will instead display a list of any files it cannot find.

DEL is an internal command. ERASE is a synonym for DEL

You may also like...

1 Response

  1. zortilo nrel says:

    I like this site very much so much excellent information.

Leave a Reply

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