Delete Files and Folders
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 delete | Command |
|---|---|
| A file | del |
| An empty folder | rmdir |
| A folder together with its contents | rmdir /s |
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
Delete multiple files
Separate multiple files with spaces.

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

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

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

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門
Delete files in bulk with wildcards
Confirm before deleting
Delete a read-only file
A file with the read-only attribute cannot be deleted as is. Add /f to force deletion.
Delete files in subfolders too
With /s, matching files in subfolders are deleted as well. The folders themselves remain.
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
Delete a folder with its contents
If the folder contains files or subfolders, add /s.
To suppress the confirmation message as well, add /q.
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.