del/erase - Delete files
When working with command prompt or batch files, it is common to manipulate files and folders on your PC.
However, there are different commands to use depending on whether you want to delete a file or a folder, and whether the folder is empty or not.
Here, we explain how to delete files, from basic usage to setting options, in an easy-to-understand way.
To delete a folder, you will need to use a different command. For more information on deleting folders, please refer to the following article:
How to delete files
To delete a file, use the
del command. You can also use the
erase command, which will produce the same result.
del command is used as follows:
del [/p] [/f] [/s] [/q] [/a[:]<file_attributes>] <file_name>
The most basic usage is to specify the path of the folder you want to delete after
The following command is an example of deleting the
sample.txt file created directly under the user directory.
By executing this command, the
sample.txt file will be deleted.
Options for the
del command has the following options.
|Displays a confirmation message before deleting
|Forces deletion of read-only files
|Displays the names of the deleted files on the screen after deletion
|Does not display a confirmation message
|Deletes only files with the specified attributes.
When you specify the
/p option, a confirmation message is displayed before deletion.
If a confirmation message is displayed, enter
Y to execute the deletion.
How to delete files with examples
Deleting files with specified attributes
To delete files with specific attributes, such as system files or hidden files, use the
The following example deletes the
sample.txt file that is both hidden and read-only.
Deleting files using wildcards
del command, you can delete multiple files at once by using wildcards.
The following example deletes files that start with
sample created directly under the user directory.
Deleting files in subfolders
del command, you can also delete files in subfolders.
The following example deletes files in the
sample folder created directly under the user directory.