DEV Community

Victor James
Victor James

Posted on • Originally published at windowscmd.com on

ERASE Windows Command

ERASE

ERASE

The ERASE windows command-line tool is to delete one or more files. This command is the same as the Del command.

CMD Line

CMD Line is a text-based interface that transfers the command from the user to the OS.

CLI-Command Line Interpreter

The command-line interpreter (CLI) for windows is CMD.EXE. Also, you can use PowerShell which can automize many system administration tasks and these tasks are not approachable in command prompt. With the help of the CLI, you can communicate with your system by typing the text in commands. As a result, your system answers to the text that you have typed previously, and then the user can proceed with the next command line that shows up.

To open the Run command Window

Run command window helps you to run programs, open the files and folders. And there are several ways to open up the run command dialog box. This run command box is useful for you to head straight to the destined program easily.

By using the Keyboard shortcut Key:

WINDOWS+R

The shortcut key method to the run command box is the most commonly used one. Also, this method is in all versions of Windows. You need to press the Windows+ R key concurrently to open the Run command dialog box.

Run command box
Run command box

What does the ERASE command do?

As we have said earlier, the Erase command deletes one or more files or file systems. Also, this command is similar to the Erase windows command. ERASE is an internal command. ERASE command is equivalent to DEL.

Syntax:


DEL [options] [/A:file_attributes] files_to_delete

Enter fullscreen mode Exit fullscreen mode

Parameter Explanation:

f iles_to_delete – A filename or a list of files , may include wildcards.

Available options:

  • P – Give a Yes/No Prompt before deleting.
  • /F – Ignore read-only setting and delete anyway (FORCE)
  • /S – Delete from all Subfolders (DELTREE)
  • /QQuiet mode , do not give a Yes/No Prompt before deleting.
  • /A – Select files to delete based on file_attributes.
File attributes
  • R – Read-only
  • -R – NOT Read-only
  • A – Archive
  • -A – NOT Archive
  • S – System
  • -S – NOT System
  • H – Hidden
  • -H – NOT Hidden
  • I – Not content indexed
  • -I – content indexed files
  • L – Reparse points
  • -L – NOT Reparse points
  • X – No scrub file attribute
  • -X – Scrub file attribute (Windows 8+)
  • V – Integrity attribute
  • -V – NO Integrity attribute (Windows 8+)

  • Wildcards : These can be combined with part of a filename

    • * Match any characters.
    • ? Match any ONE character.

In case if a folder name is given rather than of a file, all files in the folder will be deleted, but the folder itself will not be removed.

If you remove files using PowerShell, then a True/False return code ($?) will be set.

Error Levels

DEL will deliver an Errorlevel of 0 , regardless if the deleting process succeeds or fails.

So the error level is as follows,

  • % ERRORLEVEL% = 0 If the files were successfully removed.
  • %ERRORLEVEL% = 0 will occur even if the files failed to delete, or don’t exist to be deleted
  • %ERRORLEVEL% = 1 will occur if Bad or no parameters are given.

Undeletable files

  • Some of the files that are impossible to delete with Windows explorer are the files that have long file names or a trailing period or with reserved names.
  • If you want to delete those files, use either one of these syntaxes,

DEL "\\?\path to file"



"\\.\path to device"

Enter fullscreen mode Exit fullscreen mode

Example :

DEL “\?\C:\some folder\AZH64GT.”

DEL “.\C:\Work\LPT1”

  • Or else, by using the SUBST to map a drive letter to the folder containing the file, you can reduce the total path length.
  • Using RoboCopy you can Copy/Move the required files to a temporary folder and then delete the folder.

But with this RoboCopy technique is RoboCopy’s tendency to follow symbolic links , which can cause outside the source folder to be moved/ deleted.

  • After all, if you can’t delete this may be caused by the indexing service, temporarily stop the service, and then delete the file.

For permanent deletion:

The process of deleting will not prevent third-party utilities from undeleting it again. But in that case, you can turn any file into a zero-byte file to destruct the file allocation chain by using,


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

Enter fullscreen mode Exit fullscreen mode

Steps to delete a locked file:

  1. First, you need to close all applications.
  2. Then open a command prompt.
  3. Click Start , and then Shut Down , Concurrently press CTRL+SHIFT+ALT.
  4. When you keep on pressing, select Cancel in the Shut-Down Windows dialog box.
  5. And in the command prompt window, navigate to the cache location, and delete all files from the folder (DEL /s)
  6. In the command prompt, type explorer , and then press ENTER.

The DELTREE windows command-line tool is used to delete files and folders in the Older versions of Windows.

Examples:

To delete “Hello World.txt”


DEL "Hello World.txt"

Enter fullscreen mode Exit fullscreen mode

In order to Delete 3 named files


DEL file1.txt file2.txt "C:\demo\file3.txt"

Enter fullscreen mode Exit fullscreen mode

Use this to delete all files that start with the letter A


DEL A*

Enter fullscreen mode Exit fullscreen mode

To delete all files that end with the letter A


DEL *A.*

Enter fullscreen mode Exit fullscreen mode

For to Delete all files with a .doc extension


DEL *.doc

Enter fullscreen mode Exit fullscreen mode

To Delete all read-only files , use


DEL /a:R *

Enter fullscreen mode Exit fullscreen mode

In order to Delete all files including any that are read-only


DEL /F *

Enter fullscreen mode Exit fullscreen mode

If Command Extensions are disabled, it will rather display a list of any files it cannot find.

Verdict

In this guide we have seen about the ERASE command-line tool is to delete the files and folders. If you have any suggestions or questions regarding this article, let us know in the comment section, we will update it to you shortly.

Related articles

  • ERASE The Erase command deletes one or more files or file systems. Also, this command is similar to the Del windows command. ERASE is an internal command. ERASE command is equivalent to DEL.
  • ECHO The ECHO windows command-line tool is to display the message on the screen. This command turns the ON/OFF command echoing feature. ECHO is an Internal command.
  • ENDLOCAL The End local command is to end localization of environment changes in a batch file which was modified by the set local command. ENDLOCAL is an internal command.
  • IF The IF windows command-line tool performs conditionally processing in batch programs. This command is for Conditionally performing a command.
  • LGPO The LGPO windows command-line tool is for the Local Group Policy Object utility. This command automates the management of local group policy.

The post ERASE appeared first on Windows Commands- SS64 Commands.

Discussion (0)