del/erase - Delete files

Maintained on

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.

Deleted files do not go to the Recycle Bin

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.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>del sample.txt

By executing this command, the sample.txt file will be deleted.

Options for the del command

The del command has the following options.

OptionDescription
/pDisplays a confirmation message before deleting
/fAlso deletes read-only files
/sAlso deletes files in subdirectories and displays the deleted names
/qDoes 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.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>del /p sample.txt
Delete C:\Users\user\sample.txt (Y/N)?
おすすめ書籍※ 広告を含む場合があります
中小企業経営者のためのRPA入門 RPA導入を成功させる方法

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

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

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

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

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

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかる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.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>del /f /a:HR sample.txt

You can specify the following attributes with /a. Prefixing an attribute with - targets files that do not have it.

AttributeDescription
RRead-only files
HHidden files
SSystem files
AFiles ready for archiving
INot 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.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>del sample*

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.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>del sample\*

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.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>del /q sample\*

Deleting including subfolders

To also delete files in subfolders, use the /s option. The names of the deleted files are displayed.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>del /s sample\*
del does not delete folders

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 /f option.
  • 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.

Exercise

Practice Problem

Which command displays a confirmation message before deleting?

回答がサーバーに送信されることはありません
#Command Prompt #Batch Files #del #Command Line #Commands