What to do when a file won’t delete?

Understand Why a File Won’t Delete

There are several common reasons why you may not be able to delete a file in Windows:

File permissions – If you don’t have permission to delete the file, you will get an “Access denied” error. This is common with system files or files created by another user account.

Open file handles – If a program has the file open or is using it in some way, Windows will not allow you to delete it. You need to close any associated programs first.

File corruption – If the file metadata or directory entry is corrupted, attempts to delete it will fail. Running chkdsk can identify and repair file system corruption.

Hardware problems – Faulty hard drives, USB drives, etc can lead to not being able to delete files. Check Disk Management for device errors.

As you can see, there are a variety of reasons a file may resist deletion in Windows. Understanding why it occurs is the first step to resolving the issue.

Check File Permissions

One of the most common reasons a file may not delete properly is due to incorrect permissions settings. In Windows, you need to have the “Delete” permission enabled for both the file itself and the folder it is contained in.

To check permissions on a file or folder in Windows:

  1. Right click on the file and select “Properties”.
  2. Go to the “Security” tab.
  3. Check that your user account has the “Allow” permission for “Delete” both on the file itself and the parent folder.

If you do not see the “Delete” permission, you can add it by clicking “Edit” and then “Add” to grant your account the delete permission.

For further details, refer to this guide on checking file permissions in Windows 10.

Close Associated Programs

One of the most common reasons a file won’t delete is because it’s currently open in another program. To resolve this, you’ll need to close any applications that may be using the file you want to delete.

Here are the steps to close programs associated with the file:

  1. Press Ctrl + Shift + Esc to open Task Manager.
  2. Go to the “Processes” tab.
  3. Look for any processes/programs that might be using the file. Common examples include Microsoft Word, Excel, media players, etc.
  4. Select the process and click “End task” to force close the program.
  5. Closing the program should release the file and allow you to delete it.

You can also use the “Handle” tool from https://www.makeuseof.com/tag/5-ways-delete-file-use-windows/ which shows you which processes have a lock on the file.

Unlock the File

Sometimes a file can become locked or in use by another program, preventing you from deleting it. To unlock a file in use, you’ll need to close the program that is accessing it. Here are some tips for unlocking a file:

Check the file properties by right-clicking on the file and looking at the general tab to see if it says “in use” or “locked.” This will tell you if another program has locked the file.

Use Task Manager’s “Processes” tab to look for any software using the problematic file. End the tasks associated with that program to free up the file.

If you know what software normally accesses the file, close or quit that program first before trying to delete the file again.

For files locked by Windows, restarting your computer will unlock any system files in use. Be sure to restart first before attempting to delete system files.

Tools like Unlocker can force close handles that have locked a file. This software can unlock and delete problematic files.

By closing out any software using the file, you can unlock it and then retry deleting the file successfully.

Delete via Command Prompt

If a file won’t delete through normal methods, you can try using the Command Prompt to force delete it. The Command Prompt gives you access to more powerful delete commands.

Open the Command Prompt and navigate to the folder containing the file. Then use the DEL command to force delete the file. For example:

DEL myfile.txt

You can also delete folders using the RMDIR or RD command. This will delete the folder and all its contents. For example:

RMDIR foldername

The Command Prompt delete commands are very effective at removing stubborn files and folders. Just be cautious, as these commands permanently delete files with no Recycle Bin recovery. More information can be found in this guide: https://iqcode.com/code/shell/cmd-delete

Delete on Reboot

One option to delete a locked file is to schedule it for deletion upon the next restart. Windows has a built-in feature that allows you to queue files and folders to be permanently deleted the next time you reboot your computer.

To do this, simply right-click on the file or folder you want to delete and select “Delete on Reboot” from the context menu. This will add the selected item to the PendingFileRenameOperations registry key. When Windows starts up again, it will check this list and delete any entries before the desktop loads.

The benefit of this method is you don’t have to manually remember to delete items again after restarting. It can help clear out old locked files without you having to do anything. Just be aware that once queued, the files will be permanently deleted upon next reboot so use this carefully.

If the “Delete on Reboot” option is missing from your right-click menu, you can download free utilities like Delete.On.Reboot to add the capability back.

Use Unlocker Software

There are a number of software tools available that can help unlock and delete stuck files in Windows. Some popular options include:

Unlocker – This free utility by Microsoft MVP Ivo Brugner can unlock and delete locked files as well as repair folder errors. It integrates with the right-click context menu for easy use. https://www.systoolsgroup.com/pdf-unlocker.html

LockHunter – Another free file unlocker tool that can force delete stubborn files that refuse deletion. It can be run as a portable app without installation. https://listoffreeware.com/best-free-folder-unlocker-software-windows/

Systools File Unlocker – This software can unlock a wide range of file types including PDF, Word, Excel, PowerPoint and more. The free trial version allows deleting up to 2 locked files. https://free-file-unlocker.software.informer.com/

These specialized file unlocker tools provide a quick and easy way to force delete stuck files without complex command line operations or reboots. They can target the specific locked files for deletion while leaving other files intact.

Check for Viruses

Some viruses and malware are designed to prevent infected files from being deleted. The virus injects code into the file that blocks Windows from removing it, essentially locking the file in place. When you try to delete the infected file, you may get error messages like “Access denied” or “File in use.” This is a tactic used by ransomware and other malicious programs to persist on your system.

Run a full system scan using your antivirus software like Windows Defender or Malwarebytes. The antivirus should detect and remove any infections that are preventing file deletion. You may need to reboot your computer after cleaning malware for the problem files to unlock. Be sure to update your antivirus regularly to detect the latest threats.

According to How to prevent windows defender antivirus from deleting a…, you can add exclusions in Windows Defender to prevent it from automatically deleting files.

Repair Drive Errors

One potential cause of a file not deleting properly is underlying corruption or errors with the hard drive. Drive errors can sometimes prevent normal file operations like deleting. Running disk repair utilities like CHKDSK or Disk Drill can fix many common drive issues.

CHKDSK is a built-in Windows tool that scans drives and fixes logical file system errors. To run CHKDSK, open an elevated Command Prompt and type “chkdsk C: /f” to scan drive C and fix any problems found (Source). CHKDSK can repair issues like bad sectors, cross-linked files, directory errors, invalid filenames, orphaned clusters, and more. This may resolve any underlying drive problems preventing file deletion.

Third-party tools like Disk Drill can also repair drives and recover deleted files. Disk Drill scans drives and repairs various issues including lost partitions, boot sector damage, filesystem corruption, and directory errors (Source). Running Disk Drill before trying to delete files again may allow the deletion to complete successfully.

Properly repairing drive errors is crucial to ensure normal file operations like deleting files. Tools like CHKDSK and Disk Drill provide an automated way to diagnose and fix many common hard drive problems.

Recycle Bin Issues

If the file is stuck in the Recycle Bin, try restoring the file and then deleting it again. Sometimes files can become corrupted in the Recycle Bin, preventing you from permanently deleting them. To resolve this:

Right-click on the Recycle Bin icon and select Open. Find the problem file and right-click on it. Choose Restore to move the file back to its original location. Once restored, delete the file again and empty the Recycle Bin to complete the deletion. You can empty the Recycle Bin by right-clicking on it and selecting Empty Recycle Bin.

If the restore option is grayed out, the file may be too corrupted to recover. In this case, you’ll need to empty the Recycle Bin to force deletion. With the Recycle Bin open, click the File menu and choose Empty Recycle Bin. Check if the problematic file has been removed. If it still remains, a more advanced solution may be required.

Sources:

https://www.reddit.com/r/Windows10/comments/m36wje/corrupt_file_wont_delete_from_recycle_bin/