Delete a single file with the DEL command

To delete one file in Command Prompt, type DEL followed by the filename and press Enter. For example, if you want to delete a file called budget.txt that sits in your current folder, you would type DEL budget.txt and press Enter. Command Prompt will delete the file when ready without asking you to confirm.

If the file is in a different folder, you need to include the path. Type DEL C:\Users\YourName\Documents\budget.txt (replacing the path with your actual file location). You can find the full path by opening File Explorer, right-clicking the file, selecting Properties, and copying the location shown at the top.

One important difference from dragging a file to the Recycle Bin: files deleted through Command Prompt do not go to the Recycle Bin. They are removed directly. If you delete a file by mistake, recovery is much harder than if you had sent it to the Recycle Bin first.

Key Takeaways

  • The DEL command removes a file permanently without sending it to the Recycle Bin, so double-check the filename before you press Enter.
  • Type the full path to the file if it is not in your current folder, or use the CD command to navigate to the folder first.
  • You can delete multiple files at once by using wildcards like DEL *.txt to remove all text files in the current folder.
  • The /P flag lets you confirm each deletion before it happens, which is safer when you are deleting multiple files.

Navigate to the file's folder first

If you know the file is in a specific folder but do not want to type the full path, you can navigate there using the CD command. Type CD C:\Users\YourName\Documents and press Enter to move into that folder. The command prompt will now show that folder as your location.

Once you are in the correct folder, you can straightforward type DEL filename.txt without the full path. This is faster if you are deleting several files from the same folder. To see what files are in your current folder before you delete anything, type DIR and press Enter — this lists all files and folders in that location.

Delete multiple files at once with wildcards

The asterisk symbol (*) acts as a wildcard in Command Prompt, meaning it matches any characters. If you want to delete all files with a certain extension, type DEL *.txt to remove every text file in the current folder. You can also use DEL budget* to delete every file that starts with the word "budget" — for example, budget.txt, budget_2024.xlsx, and budget_old.doc would all be deleted.

Wildcards are powerful but dangerous because they can delete more files than you intended. Before you use a wildcard command, run DIR *.txt first to see exactly which files match your pattern. This way you can confirm you are targeting the right files before you delete them.

Confirm each deletion with the /P flag

If you are nervous about deleting the wrong file, add the /P flag to make Command Prompt ask you to confirm each deletion. Type DEL /P *.txt and press Enter. Command Prompt will then show you each filename one at a time and ask "Delete (Y/N)?" — type Y for yes or N for no.

This is especially useful when you are using wildcards, because you can see each file before it is removed. If you see a file you want to keep, type N and it will be skipped. This method takes longer but prevents accidental deletions.

Delete a file with spaces in its name

If a filename contains spaces, you must put the entire filename in quotation marks. For example, to delete a file called my budget report.txt, type DEL "my budget report.txt" and press Enter. Without the quotation marks, Command Prompt will think you are trying to delete a file called my and will show an error.

The same rule applies when you include a path with spaces. Type DEL "C:\Users\My Documents\my budget report.txt" with quotation marks around the entire path and filename. This tells Command Prompt to treat the whole thing as one item, not separate words.

Recover a file you deleted by mistake

If you deleted a file through Command Prompt and realized your mistake when ready, your options are limited. Files deleted this way do not go to the Recycle Bin, so you cannot restore them from there. However, if you have not written much new data to your hard drive since the deletion, recovery software may be able to retrieve the file.

Stop using your computer right away and search for a file recovery tool — common options include Recuva (free), EaseUS Data Recovery Wizard, or MiniTool Power Data Recovery. These programs scan your hard drive for deleted files that have not yet been overwritten. The sooner you run recovery software after the deletion, the better your chances of getting the file back. If the file is critical and recovery software does not work, a professional data recovery service can sometimes retrieve it, though this is expensive.

Frequently Asked Questions

Can I undo a DEL command after I press Enter?

No. Once you press Enter, the file is deleted permanently and does not go to the Recycle Bin. There is no undo function in Command Prompt. This is why it is important to double-check the filename and use the /P flag when you are unsure.

What is the difference between DEL and RMDIR?

DEL removes files. RMDIR removes folders (directories). If you try to use DEL on a folder, it will not work. Use RMDIR to delete an empty folder, or RMDIR /S to delete a folder and everything inside it.

How do I delete a file if I do not know its exact name?

Use wildcards to match part of the name. For example, if you remember the file starts with "report", type DIR report* first to see all matching files. Then use DEL report* with the /P flag to confirm each deletion before it happens.

Can I delete a file that is currently open in another program?

No. Command Prompt will show an error saying the file is in use. Close the program that has the file open first, then try the DEL command again.

What does the /S flag do with the DEL command?

The /S flag deletes a file from the current folder and all subfolders inside it. For example, DEL /S *.tmp removes all temporary files from your current location and every folder nested inside it. Use this carefully because it can delete many files at once.