- RyanTAdams.com - //blog.ryantadams.com -

Deleting Files “in Use”

If you have ever tried to delete a file, while it was still opened by a program, you probably received an error message to the effect of “Cannot delete file: Access is denied”. There are several other variations of this error, including:

All of these mean the same thing. The file is in use by a program, and you can’t delete it until that program is closed. What do you do then when there aren’t any programs actually using the file?

Sometimes, a program (or even the Windows operating system) will fail to properly “let go” of a file it was using. The surefire way to get around the above errors is usually to restart your computer. This will force the offending program to close, and clear everything out of memory. When your computer restarts, you should be able to delete the file without a hitch.

Sometimes, rebooting is inconvenient or impossible. Other times, you want to know what specific program was causing the issue to begin with. In these situations, you can use Process Explorer [1] to help. Download [1] and run Process Explorer. If this is your first time using the program you will be prompted to accept the license agreement. Then:

  1. Click “Find” on the menu bar. Select “Find Handle or DLL”.
  2. In the window that opens, type the name of the file you are unable to delete.
  3. Press search.
  4. The results will list all the process that have that file open. Hopefully there are only a few.
  5. Double click on the first result. This will take you back to the main Process Explorer window. In the lower pane you will see the file you searched for listed.
  6. Right click on the file in the lower pane. And select “Close Handle”. Confirm the action if asked.
  7. Repeat steps 1-6 until the search return no more results.

You should now be able to delete the file without encountering an error message.