Deleting a file is extremely easy in Windows or any other operating system for that matter. In Windows, you just have to right-click on the file and then click Delete option. One can also delete a file by selecting the same before pressing the Delete key.
But at times you might come across a file that can’t be easily deleted with the click of mouse button. Of course, there are number of free applications out there to help you delete a file that can’t be deleted otherwise by selecting or right-clicking on it, but more often than not files that can’t be deleted from Windows Explorer can be deleted from Command Prompt without installing third-party applications. And if you have never used the Command Prompt before, truest me, it’s not as difficult as it sounds.
Follow the given below instructions to delete a file from the Command Line in all versions of Windows.
WARNINIG: When you delete a file from the command line, the file will not be put into the Recycle Bin, which means that the file will be deleted permanently and can’t be restored from the Recycle Bin. So make sure that you no longer need the file or back it up before deleting it.
Using Command Prompt to delete a file
Step 1: In order to delete a file from Command Prompt, we recommend you open elevated Command Prompt. To do so, launch Command Prompt as administrator by typing CMD in Start menu or Start screen dialog box and then simultaneously pressing Ctrl + Shift + Enter keys.
Note that if you aren’t the admin and can’t open elevated Command Prompt, you can also try deleting the file by opening normal Command Prompt.
Step 2: To delete a specific file, you need to know the path to the file first. That is, you need to know where the file is located exactly. To know the path to the file, hold down the Shift key before right-clicking the on the file and then click Copy as path option to copy the path.
Step 3: Next, execute the following command to delete the file:
Ex: Del “E:\Test\Machine\Rain.txt ”
Command Prompt in Windows 7/8/8.1 doesn’t allow you paste using Ctrl + V command. You need to right-click and then click Paste option. However, in Windows 10, you can paste the path by pressing Ctrl + V hotkey.
And if you’re getting Could Not Find error, it’s likely because either you haven’t mentioned the extension of the file or entered wrong path. That is, you must type the extension of the file along with path and name in order to delete it.
If you want to get a confirmation prompt before deleting a file, execute the command this way:
Del /P pathtothefile
Ex: Del /P “E:\Office.docx”
And if you’re getting Access Denied, it’s likely because of its read-only attribute.
To perform force deletion of read-only file:
Del /F pathtothefile
Ex: Del /F “E:\Office.docx”
To delete all files in a folder
Del /A pathtothefolder
Note that the folder and subfolders will not be deleted.
How to hide a partition from Command Prompt guide might also interest you.