Delete Files That Cannot Be Deleted

If you're trying to delete a file and your computer isn't letting you, it's most likely because another program is currently trying to use the file. This can occur even if you don't see any programs running. Deleting these files is usually a matter of forcing the program that's using the file to close. Be careful when doing this; deleting the wrong file can have nasty effects on your system.

Steps

Windows

  1. Close any open programs and try deleting the file again. The most common reason that a file cannot be deleted is because a program is still using the file. Try closing all of your open programs and attempt to delete the file again.
    • If the file still can't be deleted, read on.
  2. Open the Command Prompt. If you can't delete a file because it is in use by another program, the quickest way to delete it is by using the Command Prompt.
    • Press the Windows key + R and type cmd to open the Command Prompt.
  3. Navigate to the location of the file you want to delete. You can see the path to the file in the Explorer window. Type cd C:\path\to\file and press Enter. Replace C: with the actual drive letter and path\to\file with the address of the folder.
  4. Type .dir and press Enter to see a list of files. Make note of the exact filename and extension of the file you want to delete.
  5. Press Ctrl + Shift + Esc to open the Task Manager. You will be forcing Windows Explorer to close.
  6. Select the .Processes tab and select explorer.exe or "Windows Explorer". Click the End task button. This will close your desktop, leaving just the Command Prompt and any other open windows.
  7. Return to the Command Prompt and type .del . This will attempt to delete the file that you specify. Make sure to include the full name and extension.
  8. Delete the containing folder if you still can't delete the file. Sometimes, deleting the folder will allow you to delete the file that it contains. Keep in mind that deleting a folder will delete all of its contents. Type rmdir /s and press Enter.[1]
  9. Try booting into Safe Mode if you can't delete the file. If your file still cannot be deleted, you may need to boot into Safe Mode. This will load only the essential processes, hopefully allowing you to delete your file.
    • Reboot your computer and rapidly hit F8 until the Advanced Startup menu appears.
    • Select Safe Mode with Command Prompt from the menu. Windows will load its essential files and then take you directly to the Command Prompt.
    • Follow the steps above to navigate to your file and try deleting it again.
  10. Try deleting using the file's short name. Sometimes odd characters can cause problems with deleting the file. Using the file's "short name", or DOS-compatible name, may help.
    • Navigate to the file's directory and type dir /x.
    • Note the short name of the file (i.e FILENA~1.XYZ).
    • Type del and press Enter.

Troubleshooting

  1. Use a Linux Live CD to access your files. This is a lite operating system, usually Linux, that you boot from a disc. Using a Linux Live CD will allow you to access all of your files without booting into Windows, meaning no Windows processes will be locking them.
    • Install-Knoppix-Linux.
    • After booting into the Linux environment, you'll be able to access the hard drive and delete any file that you weren't able to delete before. Always be careful when deleting system files.
  2. Check your disk for errors. If you are receiving an error message stating that your disk may be corrupted, the corruption could be causing your file to be undeletable. If this is the case, you'll need to try repairing the disk before you can delete the file.
    • Open the Command Prompt, type chkdsk /r and press Enter.
    • Reboot your computer if prompted and allow your disk to be scanned. The chkdsk process may take several hours to complete. It will attempt to automatically fix any errors it comes across, but the presence of errors likely indicates that your disk will be failing in the near future.
  3. Take ownership of troublesome files. Sometimes files are created that you don't have the permission to delete. In order to remove these files, you'll need to take ownership of the file.
    • Boot into Safe Mode.
    • Right-click on the file or folder you want to delete.
    • Click the Security tab.
    • Click Advanced and then Owner.
    • Check the box next to your user name for "Full Control".
    • Click Apply and then try deleting the file or folder again.

Mac OS X

  1. Determine which program is preventing the file from being deleted. The most common reason you can't delete a file in OS X is because a program is currently using the file. This process will determine which program is holding the file hostage.[2]
    • Open "Terminal" in the Utilities folder.
    • Type lsof and then drag the file that you're trying to delete into the terminal window. Press Return to see the program that is currently using the file.
    • Make note of the COMMAND and PID columns. The COMMAND is the name of the program that is locking the file, and the PID can help you force it to close.
  2. Close the program normally if possible. If the program is open and visible, close it using it's normal closing procedure. If the program refuses to close, you can try Force-Quit-an-Application-in-Mac-OS-X.
    • You can open the "Activity Monitor" in the Utilities folder to list all of your active processes. You can use the PID column in Activity Monitor to match the PID of the process you uncovered using the Terminal. Select the process you want to close and click "Quit Process"
  3. Try the "Secure Empty Trash" command when emptying the Trash. This attempts to unlock locked files that have been placed in the Trash before they are deleted. Use this if you are receiving messages about locked files when attempting to empty the trash.[3]
    • Hold the Option key when you right-click the Trash to perform a Secure Empty Trash command. This will delete most files that are locked.

Warnings

  • Always be careful when deleting files that are locked, as this typically occurs when you are trying to delete a system file. Deleting the wrong files can render your system inoperable until you reinstall your operating system.

Related Articles

Sources and Citations