How to Fix: File or Folder in Use (and Can't be Deleted)

Dennis Faas's picture

Infopackets Shelly R. writes:

" Dear Dennis,

Every once in a while, when I try and delete a folder on my network share, Windows tells me that 'This action can't be completed because the folder or file in it is open in another program'. I click the 'Try again' button multiple times but that rarely ever works. Can you please tell me why this keeps happening and what I can do to delete the file / folder? "

My response:

The reason why you receive the 'File in use' error (or 'Folder in use' error) is exactly that - the file or folder is in use by some other program, however, Windows isn't saying specifically which program has the file or folder in use (sometimes it does). Oftentimes this can happen - especially over a network share - because the file or folder's thumbnail is being reconstructed; usually waiting a few seconds to 'retry' resolves this issue, but not always.

In cases like this you can use third party programs such as 'unlocker' to unlock the file or folder in use, but based on my experience, it doesn't always work. As such I'll explain how to find out which file or folder is in use using an alternative (and better) method, using Process Explorer.

How to Fix: File or Folder in Use (and Can't be Deleted)

  1. First, download Process Explorer if you have not already, then place a shortcut to the program on your desktop.

    Tip: you can simulate a 'folder in use' error by making a temporary directory, then use the command line to "cd" (change directory) to that folder, then try and delete the same folder using Windows Explorer. To do the simulation: click Start, then type in "cmd" (no quotes); wait for CMD.EXE or Command Prompt to appear in the list, then right click it and select "Run as Administrator". Next, highlight the text below with your mouse:

    c:
    mkdir \temp
    cd \temp
    echo this is a dummy line

    Right click over the above text, then select Copy from the dialogue menu. Next, go to the administrative command prompt and right click in the middle of the window. The text you copied in the previous step should now be output to the command line. When that is complete, go to "My Computer" or "This PC", double click the C drive to open it, then locate the "Temp" folder and attempt to delete the folder. You should see a message stating that "The folder is in use" error.
     
  2. Now that you have a "file / folder in use" error, launch Process Explorer. From the "Find" menu, select the option "File Handle or DLL". A new window will appear with the title "Process Explorer Search". In the "Handle or DLL substring" field, type in the file or the folder which is in use that you would like to move / delete, etc. In our example, the folder we're trying to delete is called "Temp" - so enter that in, then click the Search button.
     
  3. The search will be performed in the same window. When it completes, please note the headings "Process", "PID", "Type", and "Name" under your search query. Going back to our example, we're searching for "Temp" - as such, you should see something like "Cmd.exe" under the Process heading, then a number for the PID (process ID number), the Type as "File", and the Name as "C:\Temp".

    This is basically saying that "C:\Temp" is in use by the process "cmd.exe", or the command prompt. If you left click the PID in the search result window, it will then select the same PID in the main Process Explorer window. In the main Process Explorer window, you can press DEL on the keyboard to end the task, which will then allow you to delete the file / folder.

    Tip: only end a task that you know will not result in loss of data. For example: if you attempted to delete a document which was already opened by Microsoft Word ((WinWord.exe), AND if you tried to end the Microsoft Word task, then anything that was previously typed into the document while MS Word was open may be lost if it was not previously saved. In that case, a better approach would be to go to the task in question that is causing the "file in use" error (in this case - MS Word), close the document, then delete it.

I hope that helps.

Got a Computer Question or Problem? Ask Dennis!

I need more computer questions. If you have a computer question - or even a computer problem that needs fixing - please email me with your question so that I can write more articles like this one. I can't promise I'll respond to all the messages I receive (depending on the volume), but I'll do my best.

About the author: Dennis Faas is the owner and operator of Infopackets.com. With over 30 years of computing experience, Dennis' areas of expertise are a broad range and include PC hardware, Microsoft Windows, Linux, network administration, and virtualization. Dennis holds a Bachelors degree in Computer Science (1999) and has authored 6 books on the topics of MS Windows and PC Security. If you like the advice you received on this page, please up-vote / Like this page and share it with friends. For technical support inquiries, Dennis can be reached via Live chat online this site using the Zopim Chat service (currently located at the bottom left of the screen); optionally, you can contact Dennis through the website contact form.

Rate this article: 
Average: 4.8 (5 votes)

Comments

steve1's picture

Often deleting individual files in the folder then deleting the folder will work. If it doesn't you will find which file can't be deleted blocking the whole process.

tipsnews_7859's picture

I have run into all the reasons for this issue. Bottom line, I believe, is that Windows forgets it needs to do housecleaning. Open File Explorer and it won't be long b4 you run into this issue. SOMETIMES if I close FE and reopen, the issue goes away. By then I have forgotten what file/folder I want to delete. I have had to reboot my system to get the issue to resolve.
IMHO, it is a bug in the OS.

bronzac1_7888's picture

I used to stop/restart the explorer.exe process to allow file/folder deletion. The donationware utility Unlocker is quick and handy. It runs from the right click menu to kill any locking handles and delete a locked file/folder.