- You can use the “del” command to delete a single file, multiple files, files that contain a specific word, files with a specific extension, and all files in a folder at once.
- The Command Prompt can also help remove or delete stubborn files that you cannot delete from File Explorer.
- Deleting files using commands is also helpful when you want to delete a large number of files.
Generally, deleting a file in Windows is a simple process. All you have to do is select the file you want to delete and press the “Delete” key on your keyboard or right-click on the file and select the “Delete” option.
If you cannot delete a file using File Explorer, you can use the Command Prompt to delete files in Windows 10 and 11. The Command Prompt offers a quick and easy way to delete a single file, multiple files, files with a specific extension, or read-only files. The best thing is that this works even if the file is locked, in use, or blocked from deletion.
In this short tutorial, let me walk you through the process of deleting a file using cmd.
Table of contents:
- How to delete a file using CMD
- How to delete all files in a folder using CMD
- How to delete files with a specific extension using CMD
- How to delete read-only files using CMD
Important note: Files deleted using cmd will skip the Recycle Bin. That means you cannot restore a deleted file from the Recycle Bin. So, be careful while using Command Prompt to delete files in Windows.
How to delete a file using CMD
To delete a single file, all you need to do is execute a single command with the file name.
- Select the “Start” icon on the taskbar.
- Search for “Command Prompt.”
- Click on the “Run as administrator” option.
- Use the “cd C:\path\to\folder” to navigate to the folder.
- Run the “del filename.ext” command to delete the file. Replace “filename.ext” with the actual file name and extension.
Steps with more details:
First, search for “cmd” in the start menu, right-click on Command Prompt and select “Run as administrator.” This action will open an elevated command prompt.
Note: The elevated Command Prompt is required to delete locked files, files belonging to other user accounts, etc.
Once the Command Prompt window opens, use the “cd” command to go to the folder where the files you want to delete are located. For instance, the files I want to delete are in a folder named “del” on my desktop. So, I use the following command.
Note: If the folder is located in another partition, like the D drive, execute the “DriveLetter:” command while replacing “DriveLetter” with the actual drive letter. For example, to change the directory to D drive, you have to execute the “D:” command. Once in the drive, you can use the “cd” command to navigate to the target directory.
Once you are in the folder, run the below command to delete a file. Don’t forget to replace
<filename> with the actual file name along with its file extension. In my case, the file name is
If the file is locked in some way, use the below command to force delete the file.
del /f <filename>
On successfully deleting the file, you will not see any confirmation message. So, that’s a good thing. If there is a problem, the command prompt will show an error message.
How to delete all files in a folder using CMD
The Command Prompt offers a simple command to delete multiple files in a folder at once. Whether you need to delete specific files or all files in a folder, cmd provides the option to do so. I will show how to use the command to delete multiple files in both situations. Follow the one that best suits your needs.
Here’s the cmd to delete multiple files:
First of all, open Command Prompt as administrator from the Start menu.
Once the command window opens, use the “cd C:\folder\path” to go to the folder with the files you want to delete.
Next, to delete multiple specific files at once, execute the below command while replacing <filname1>, <filename2>, etc., with the actual file names along with the file extension. You can specify as many file names as you want.
del <filename1> <filename2>
You can use the “*” (wildcard) character to delete all the files in a folder. Here’s the command to remove all files in a directory.
Since we are deleting all the files in a folder, the Command Prompt window will warn you. Simply type “Y” and press “Enter” to confirm file deletion.
You can also use the wildcard character to delete all files that start with a specific name in a folder. For that, use the below syntax. For instance, the below command will delete all the files in a folder that start with the name “image.”
Alternatively, you can also delete files that contain a specific word. The below command will delete all the files with the name that contains the “tFile” word.
How to delete files with a specific extension using CMD
Sometimes, you might want to delete all the files with a specific extension. For instance, maybe you want to delete all the “.png” files in a folder. In that case, we can use the same wildcard character.
Here’s the command to delete files that have a specific file extension, then you can use below command. Don’t forget to replace “fileExtension” with the actual file extension, like png, jpg, zip, etc.
For example, to delete all the PNG files in a folder, the command looks something like this.
Use the below command to delete all files with a specific name and extension. Don’t forget to replace the file name and extension to match your needs.
How to delete read-only files using CMD
Unlike regular files, read-only files are protected and difficult to delete by design. If you try to delete a read-only file using the normal commands shown above, you will receive the “Access is denied” error message.
First, open the command prompt from the Start menu and use the “cd C:\path\to\folder” command to go to the folder with the read-only file.
Once you are here, use one of the below commands to delete the read-only file. Replace <filename> with the actual filename and extension.
del /f <filename>
del /a:r <filename>
CMD to delete files in Windows – Conclusion
As you can see, commands to delete files in Windows are pretty simple and straightforward. With the commands and flags shown in this tutorial, you can delete individual files, read-only files, multiple files, or even all files in a folder. You can also use the Command Prompt to delete files that are locked, in use, or blocked from deletion. The steps shown above are handy when you need to delete a large number of files or when you cannot delete a file using the traditional File Explorer method.
I hope this simple and easy Windows how-to guide helped you.
If you are stuck or need help, send an email, and I will try to help as much as possible.
If you like this article, you might also want to know how to force delete locked files in Windows and how to delete a single URL from Chrome and Firefox’s auto-complete history.