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.
Files deleted with del are permanently removed instead of being moved to the Recycle Bin as in File Explorer. When using wildcards or /s, check the targets with the dir command first.
The 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 file you want to delete after del.
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
The del command has the following options.
| Option | Description |
|---|---|
/p | Displays a confirmation message before deleting |
/f | Also deletes read-only files |
/s | Also deletes files in subdirectories and displays the deleted names |
/q | Does not display a confirmation message (including for wildcards) |
/a[:attributes] | Deletes only files with the specified attributes. |
/p option
When you specify the /p option, a confirmation message is displayed before deletion.

中小企業経営者のためのRPA入門 RPA導入を成功させる方法

60分でわかる! AIエージェント 超入門

コマンドラインの黒い画面が怖いんです。

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門
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 /a option.
The following example deletes the sample.txt file that is both hidden and read-only. The /f option is also required to delete a read-only file.
You can specify the following attributes with /a. Prefixing an attribute with - targets files that do not have it.
| Attribute | Description |
|---|---|
R | Read-only files |
H | Hidden files |
S | System files |
A | Files ready for archiving |
I | Not content-indexed files |
Deleting files using wildcards
With the 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 a specific folder
To delete the files in a specific folder, specify the folder.
The following example deletes the files directly under the sample folder in the current directory.
Even del sample (a folder name only) deletes all files directly under that folder. Without /q, a confirmation message is displayed before deletion.
Deleting without confirmation
When deleting files automatically in a batch file, a confirmation prompt can stall processing. Specify the /q option to delete without confirmation.
Deleting including subfolders
To also delete files in subfolders, use the /s option. The names of the deleted files are displayed.
del deletes files only. To delete a folder itself, see the following article.
When deletion fails
del fails in cases such as the following.
- The file does not exist: “Could Not Find” is displayed.
- The file is read-only: “Access is denied” is displayed. Re-run with the
/foption. - The file is in use by another program: “The process cannot access the file because it is being used by another process” is displayed. Close the program and run again.