Delete Files and Folders
Maintained on November 14, 2026
Table of Contents Delete files Delete a single file Delete multiple files Delete files in bulk with wildcards Confirm before deleting Delete a read-only file Delete files in subfolders too Delete folders Delete an empty folder Delete a folder with its contents Example: batch deletion in a batch file When deletion fails, and how to avoid mistakes Related articles Exercises 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 delAn empty folder rmdirA folder together with its contents rmdir /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
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
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"
Delete files in bulk with wildcards
- □ ×
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
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
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
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
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
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
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.
When deletion fails, and how to avoid mistakes
Hidden files are not deleted : by default del skips files with the hidden attribute. Add /a, as in del /f /a "path\*".
Never run rmdir /s /q with an empty variable : when you build the path from a variable such as rmdir /s /q "%WORKDIR%", if you append a path such as "%WORKDIR%\sub", an unset variable turns it into \sub at the drive root. Check first with if not defined WORKDIR exit /b 1.
“In use” errors : deletion fails while another program has the file or folder open. Close that program and run the command again.
Related articles
Exercises
Try more practice questions 171 questions by topic. Answer in your browser and check instantly. Start practicing →
#Command Prompt
#Batch Files
#File Operations
Related Articles