Delete Files and Folders

Maintained on

When cleaning up in a batch file, the command you use depends on whether the target is a file or a folder.

In Command Prompt, use them as follows.

What to deleteCommand
A filedel
An empty folderrmdir
A folder together with its contentsrmdir /s
Deletion in Command Prompt is basically irreversible

Items deleted with del or rmdir normally do not go to the Recycle Bin. Always double-check the target path before running them.

Delete files

Use the del command to delete files.

Delete a single 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 "%USERPROFILE%\Documents\disposable.txt"

Delete multiple files

Separate multiple files with spaces.

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

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

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

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

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

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

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門

Delete files in bulk with wildcards

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

Confirm before deleting

- □ ×
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 "%USERPROFILE%\Documents\output.txt"

Delete a read-only file

A file with the read-only attribute cannot be deleted as is. Add /f to force 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 /f "%USERPROFILE%\Documents\readonly.txt"

Delete files in subfolders too

With /s, matching files in subfolders are deleted as well. The folders themselves remain.

- □ ×
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 "%USERPROFILE%\Documents\disposable\*.tmp"
del does not delete the folder itself

del deletes files, not folders. Note that if you specify a folder, all files directly inside it are deleted. To delete a folder itself, use rmdir.

Delete folders

Use the rmdir command to delete folders. Its short form rd works the same way.

Delete an empty folder

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>rmdir "%USERPROFILE%\Documents\disposable"

Delete a folder with its contents

If the folder contains files or subfolders, add /s.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>rmdir /s "%USERPROFILE%\Documents\disposable"

To suppress the confirmation message as well, add /q.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>rmdir /s /q "%USERPROFILE%\Documents\disposable"
Do not use rmdir to delete a single file

rmdir is a command for directories. Use del to delete a single file.

Example: batch deletion in a batch file

@echo off
setlocal

set "WORKDIR=%USERPROFILE%\Documents\disposable"

del /q "%WORKDIR%\*.tmp" 2>nul
if exist "%WORKDIR%" rmdir /s /q "%WORKDIR%"

endlocal
exit /b

This example first deletes the temporary files, then deletes the working folder together with its contents.

Exercises

Practice Problem

Which command deletes a folder together with the files inside it?

回答がサーバーに送信されることはありません
Practice Problem

Which command deletes a single file?

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