The del command removes files from your computer through Command Prompt
To delete a file in Command Prompt, you type del followed by the filename and press Enter. Command Prompt is the text-based program built into Windows that lets you control your computer by typing commands instead of clicking. Deleting through Command Prompt works the same way as dragging a file to the Recycle Bin — the file goes to Recycle Bin first, so you can recover it if you change your mind.
The basic command is: del filename.txt (replace "filename.txt" with your actual filename). If the file is in a different folder than the one you are currently in, you need to tell Command Prompt where to find it first. This guide walks you through the steps for both situations.
Key Takeaways
- Open Command Prompt by typing "cmd" in the Windows search box, then type del filename.txt to delete a file in your current folder.
- If the file is in a different folder, navigate to that folder first using the cd command, or type the full path: del C:\Users\YourName\Documents\filename.txt.
- Files deleted through Command Prompt go to Recycle Bin and can be recovered unless you empty the bin or use the /P flag to confirm deletion first.
- Use del *.txt to delete all files with a .txt extension in the current folder, but be careful — this deletes multiple files at once.
- If you get an error message, the file may be open in another program, protected, or the filename may be spelled differently than you typed.
Open Command Prompt and navigate to your file
First, open Command Prompt. Click the Windows search box at the bottom left of your screen, type cmd, and press Enter. A black window with white text will open. This is Command Prompt.
When Command Prompt opens, you are in your user folder (usually something like C:\Users\YourName). If your file is on your Desktop or in Documents, you need to navigate there first. Type cd Desktop to go to your Desktop folder, or cd Documents to go to Documents. Press Enter after each command. The text at the beginning of the line will change to show which folder you are in.
If your file is nested deeper — for example, inside a folder called "Projects" on your Desktop — type cd Desktop\Projects and press Enter. You can chain folder names together with backslashes to move through multiple levels at once.
Type the del command with the correct filename
Once you are in the folder where your file lives, type del followed by a space, then the exact filename. For example: del report.pdf or del budget2024.xlsx. Filenames are case-sensitive in Command Prompt, so Report.pdf and report.pdf are technically different — though Windows usually finds the file anyway.
If you are not sure of the exact filename, type dir and press Enter. This shows a list of all files in the current folder. Find the filename you want to delete, copy it exactly (including the extension like .pdf or .docx), then type del and paste the filename.
Press Enter after you type the command. If the file deletes successfully, Command Prompt returns you to the prompt with no message. If you see an error, read the section below on troubleshooting.
Delete a file using its full path without navigating first
If you do not want to navigate through folders, you can type the complete path to the file in one command. Type del followed by the full path in quotes. For example: del "C:\Users\YourName\Documents\report.pdf". The quotes tell Command Prompt to treat the whole path as one item, which matters if any folder names have spaces in them.
To find the full path, open File Explorer, right-click the file, and select "Copy as path". Then paste it into Command Prompt after the del command. This method is slower than navigating, but it works if you only need to delete one file and do not want to move through multiple folders.
Delete multiple files at once using wildcards
The asterisk symbol (*) is a wildcard that means "any characters". You can use it to delete groups of files that match a pattern. For example, del *.txt deletes all .txt files in the current folder. del report* deletes all files that start with "report" (like report.pdf, report.docx, report.xlsx).
Be very careful with wildcards. del *.* deletes every file in the current folder with any extension. If you are not certain, use dir first to see which files match your pattern before you run the delete command. Command Prompt does not ask for confirmation unless you add the /P flag: del *.txt /P will ask you to confirm each deletion one at a time.
Recover a deleted file from Recycle Bin
When you delete a file through Command Prompt, it goes to Recycle Bin just like when you delete through File Explorer. Open Recycle Bin (search for it in the Windows search box), find your file, right-click it, and select "Restore". The file returns to its original location.
If you have already emptied Recycle Bin, recovery is much harder and may not be possible. The only option is to use data recovery software, which is not may provide to work. This is why it is a good idea to double-check the filename before you press Enter on a delete command, especially if you are using wildcards.
Troubleshoot common error messages
If you see "The system cannot find the file specified": The filename is spelled wrong, or you are in the wrong folder. Type dir to list all files in the current folder and check the exact spelling. If the file is not listed, use cd to navigate to the correct folder.
If you see "Access is denied": The file is open in another program, or you do not have permission to delete it. Close any programs that might be using the file (like Word if it is a .docx file, or your browser if it is a downloaded file). If the file is protected, right-click it in File Explorer, select Properties, and uncheck "Read-only" under the General tab.
If you see "The filename, directory name, or volume label syntax is incorrect": Your path has a typo, or a folder name contains spaces and you forgot the quotes. Check the path carefully, and remember to put quotes around paths with spaces: del "C:\Users\YourName\My Documents\file.txt".
Frequently Asked Questions
Can I undo a delete command in Command Prompt?
Yes, if you have not emptied Recycle Bin. Open Recycle Bin, find the file, right-click it, and select Restore. The file goes back to where it was. If Recycle Bin is already empty, the file is much harder to recover and may be gone permanently.
What is the difference between del and rmdir?
del deletes files. rmdir deletes folders (directories). If you try to use del on a folder, you will get an error. Use rmdir foldername to delete an empty folder, or rmdir /s foldername to delete a folder and everything inside it.
How do I delete a file with a space in its name?
Put the filename in quotes: del "my file.txt". Without quotes, Command Prompt treats the space as a separator and looks for a file called "my" instead of "my file.txt".
Can I delete a file that is currently open?
No. You will get an "Access is denied" error. Close the program using the file first (like Word, Excel, or your browser), then run the delete command again.
What does the /P flag do?
The /P flag makes Command Prompt ask for confirmation before deleting each file. Type del *.txt /P and Command Prompt will ask "Delete [filename]?" for each .txt file. Type Y and press Enter to delete, or N and press Enter to skip it. This is useful when you are using wildcards and want to be careful.