The process of deleting a file in Windows is simple and straightforward. You need to select a file and then press delete or right-click on the file and select Delete to remove the file. You can also use the Shift + Del shortcut to force Windows to delete the file without sending it to the Recycle bin.
However, there are some situations where you can’t delete a file at all, and the usual methods will result in some error messages. In such cases, you need to rely on the command-line interfaces to force the deletion or resolve the root of the problem causing such issues.
Through Command Line Interface
You can also use the command-line interface tools like Command Prompt and PowerShell to forcefully delete a file in Windows.
However, the commands can’t remove hidden or read-only files on their own, so you need to use the force parameters (/f or -force) alongside in such cases.
On Command Prompt
- Open Run by pressing Windows key + R.
- Type
cmd
and press Ctrl + Shift + Enter to open the Elevated Command Prompt. - Type the command
del /f /q “Full path of file”
and press Enter to force delete the file.
For instance, if you wish to deleteFile1.txt
insideD:\Folder
, you need to enterdel /f /q “D:\Folder\File1.txt”
On PowerShell
- Open Run.
- Type
powershell
and press Ctrl + Shift + Enter to open Windows PowerShell as admin. - Use the cmdlet
Remove-Item -Path “Full path of file” -Force
to delete the file. E.g.,Remove-Item -Path “D:\Folder\File1.txt” -Force
By Replacing the File
Another way you can forcefully delete a file is by replacing the file. This way, you can delete some files that you couldn’t by using the above methods. Also, keep in mind that the file won’t go to the Recycle bin as well.
- Create another file in another location with the same name as the file you want to delete.
- Copy or move the new file to the folder containing the old file.
- Accept the prompts when it asks you if you wish to overwrite the file.
- Then, try deleting the file the normal way.
By Booting into Safe Mode
If some application is currently using or holding a file, trying to delete the file results in an error message that says, “The action can’t be completed because the file is open in another program.”
You can try looking for the application that is using the files, close it or end it from the Task Manager and then delete the file. If you don’t know which app it is, restart your PC and delete the file.
But if the application is a startup process, restarting may not make the process release its hold on the file. You will need to boot in safe mode to be able to remove the file in this scenario.
- Open the Start menu and click on the power button. Press and hold the Shift key and then click Restart. It will load the Advanced Startup options.
- Here, select Troubleshoot > Advanced options > Startup Settings > Restart.
- After the reboot, you’ll see the startup settings again. Press F4 or 4.
- Now you can use any method to delete the file after logging in to a user account.
Modifying Permissions
You can only delete a file if your current user account or user group has full ACL permissions for the file. If not, you’ll get an error message like “You need permission to perform this action.”
You need to change the security settings to be able to delete the file.
- Log in to an Administrator account.
- Right-click on the file and select Properties.
- Go to the Security tab.
- Click on Advanced and select Change next to Owner.
- Type
Administrators
or the user account name and hit Check Names. The name should now show “Computer Name”\“user name” or “Computer Name”\Administrators. - Click OK > OK.
- Click Edit and select the user account.
- Check Full control and click OK > OK.
- If the account is not there,
- Select Add.
- Type
Administrators
or the user account name and hit Check Names. Then, click OK. - Check Full control and click OK > OK.
- Now delete the file the normal way or through the Shift + Del hotkey.
Using Robocopy to Mirror an Empty Folder
In some rare cases, you may get files that are not being used by another process but are particularly difficult to remove. For instance, if somehow a filename contains a space at the end, Windows will show the file but treat it as if it’s not there. There are also other scenarios where the same happens.
This file won’t have any security information, and you can’t modify or delete it. If you try to do so, you’ll get the error message: “Could not find this item.”
The easiest way to forcefully delete the file in such cases is to make it the only file inside a folder and then mirror an empty folder to this one.
- First, move all the folders and files from the directory containing the file somewhere else. For example, if you wish to remove
D:\Folder\File1 .txt
(notice the space at the end), move all contents inside theD:\Folder
folder to another location. - Then, create a new folder anywhere. In this case, inside
D:
asEmpty
, so its path isD:\Empty
. Don’t put anything inside the folder. - Open the Command Prompt.
- Type
robocopy “New empty folder’s path” “Path of the file’s folder” /mir
and press Enter.
Make sure to replace all the file paths appropriately. In this example, it would berobocopy “D:\Empty” “D:\Folder” /mir
Note: If you encounter any error messages, such as 0x80070570: The file or directory is corrupted and unreadable, it represents the drive sectors containing the file is corrupted. You can try running chkdsk before attempting to delete the file in such cases.