190

Sometimes when I'm working in Windows I'll get this prompt when I try to delete a directory:

Folder In Use
The action can't be completed because the folder is open in another program
Close the folder and try again.

However, the folder isn't "in use" at all, and I don't have it open. So how can I delete it short of rebooting?

Cfinley
  • 1,435
Factor Mystic
  • 13,015

18 Answers18

269

There's a native GUI for Windows:

Start>>All Programs>>Accessories>>System Tools>>Resource Monitor (or Run resmon.exe)

You can search for the "Associated Handles" using the searchbox (circled in red), and right click the process you want to end.


As an example, in the image below I could not delete my Eclipse directory. Searching for the Eclipse associated handles showed that the adb.exe had a handle to the directory. After ending the adb process, I could then delete the Eclipse directory.

enter image description here

bcorso
  • 2,791
112

This answer is old, but seems to still get traffic. As noted below, there is a built in tool in Windows now:

Start → All Programs → Accessories → System Tools → Resource Monitor (or Run resmon.exe)

You can get more info in the answers below this one. The rest of this answer is no longer as relevant.


Process Explorer from Sysinternals will let you search through the handles and DLLs. Search for the directory and find out which process is "using" the folder.

From there, you have the ability to either shut down that process, or just close that particular file handle. Be sure about what you're doing when working with the file handle directly, and make sure it's not being used by some important process.

Marc Reside
  • 1,764
19

Unlocker and WhoLockMe don't work on 64-bit Windows. I use LockHunter.

Joe
  • 191
8

I've had that happen to. Sometimes I can resolve the issue by deleting the contents first, then the folder(empty).

kpoehls
  • 816
7

When using tools that forces file handles closed (like the previously-mentioned Unlocker), keep in mind that doing so might cause serious problems. (See this article by Raymond Chen.) Make sure you know which applications are using the file and that none of them are doing anything important.

It's safer to try shutting down the applications first instead of just forcing the handle closed.

Bob
  • 63,170
Brant Bobby
  • 2,576
7

This REG script will give you a "View Handles" right click context menu item which will invoke the Sysinternals handle utility to see all open handles to the file or folder that you right clicked on.

Put handle.exe from Sysinternals into a location that is accessible from your path.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\AllFilesystemObjects\shell\Handle]
@="View &Handles"

[HKEY_CLASSES_ROOT\AllFilesystemObjects\shell\Handle\command]
@="cmd.exe /k handle -a -u \"%1\""
Oliver Salzburg
  • 89,072
  • 65
  • 269
  • 311
5

I use Handle from SysInternals (now Microsoft). You can type in part of the folder name to see which process has a handle on that folder and then kill the handle.

handle64.exe -nobanner "<path>"

For example:

command output from commandline

Like others have mentioned, killing the handle can cause serious problems.

slolife
  • 1,283
3

The quickest and simplest approach is to use Handle, as mentioned by slolife, rather than using Process Explorer. They're both from Mark Russinovich @ Microsoft.

Don't be surprised to find that explorer.exe is the culprit, as I did today. Apparently there is an official way to restart explorer.exe, but I seem to be getting away with killing it and starting it back up again it in Task Manager.

2

When I was on XP I used WhoLockMe to find out what programs had files open and locked. The most recent version I could find doesn't mention Vista, but it'd be worth a shot.

Sometimes, you can delete it from the inside out manually. Just navigate all the way down in the hierarchy, delete all files, move up a directory, and repeat. Not sure why Windows can't do this itself, but it sometimes works for me.

tghw
  • 874
2

If by “not in use”, you mean there are no open handles to it, then make sure that the Application Experience service is not disabled. If so, set it to manual:

Run dialog (or command prompt):

  sc config AeLookupSvc start= demand
Synetech
  • 69,547
1

In order to delete a folder/program that says you can't delete it because is open somewhere else.

  • Click start button
  • Type Taskmgr
  • In the new window that opened, under process tab, look for the folder/program you're trying to delete.
  • Right click it and End Task
  • Go back to the folder/program location and you should be able to delete it now
Factor Mystic
  • 13,015
Hector
  • 11
1

oft times the handle that is locked is internet explorer, i either close it in task manager, then delete the file or folder or close explorer...often a folder has a txt file that is open and that will be the handle that won't let u delete folders/files...just close the txt file and then u should be fine, u can now delete ur folder.

1

I've had the same problem with a memory flash (16 gb - irrelevant probably) and it wouldn't let me delete a folder. I tried every -freaking- solution found on internet (hiding thumbnails, deleting the folder from the cmd prompt with explorer.exe shut down, everything..) and nothing worked. What made it work? Well, this:

  1. Select all the files inside the folder
  2. Right click on them and select "Cut"
  3. Go back to the root folder
  4. Paste them
  5. Delete them

That worked just fine for me. Hope I helped. :-)

Marco
  • 11
0
  1. Find the file that you want to delete.

  2. Rename it to anything you like.

  3. Delete it.

karel
  • 13,706
0

Had a file docs.zip in use by WinSCP.

  1. I created a new file using same name docs.zip
  2. Pasted over existing docs.zip and the old file got replaced by new same named file.
  3. Then I deleted the newly copied file docs.zip all together.

Good Luck

0

So there are already some good answers, but I'm going to contribute something new, which is what I used to resolve this same issue earlier today.

I used Python. I know, I know, it's not native to Windows, but it's very a very common utility for sysadmins, developers, and super users, and you can knock this out with a simple oneliner:

from shutil import rmtree; rmtree('C:\path\to\folder')

...bingo bango.

0

Try Ctrl + Shift + Esc > "programs", then right click the one you want to deactivate and choose deactivate. Then delete it again!

(My OS is in Swedish so the translations might not be exactly the same! but you get it!)

slm
  • 10,859
johan
  • 1
-3

go into the folder all the way down to the file or files being executed. when you try to delete this file it will give you what process it is running . write that down, then go to the task manager and end that process .. after that you can delete the folder.