How do I delete a folder that's in use?

142

53

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?

Factor Mystic

Posted 2009-07-15T17:15:04.147

Reputation: 11 212

2

I find this occurs most often when working with Outlook and .msg files, in which case closing Outlook stops the "Folder In Use" error. See also discussion on this Microsoft Community question.

– Air – 2015-11-23T19:17:07.917

Answers

84

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

Posted 2009-07-15T17:15:04.147

Reputation: 1 484

4There is now a native GUI for Windows, see my answer below. – bcorso – 2014-06-27T20:48:06.220

3*Native GUI /built into/ Windows (Resource Monitor) see below. – Jamie Pate – 2014-11-07T05:43:32.920

In my case, Process Explorer was not able to find the handle, but the Resource Monitor (see other answer) was capable. – Bart Verkoeijen – 2016-03-01T06:34:59.827

7But how I find directory which is used by process? – Johnny_D – 2013-09-11T10:14:52.047

2Use Ctrl-F and enter the name of the folder above the one you are trying to delete. – MikeMurko – 2014-05-06T20:58:30.560

192

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

Posted 2009-07-15T17:15:04.147

Reputation: 2 021

5This trick highlighted the process that was giving me grief :) – Pure.Krome – 2014-08-28T11:32:50.110

2Resource Monitor requires administrator credentials. – Air – 2015-11-23T19:09:57.513

I have a locked folder on my desktop that resource monitor does not list as being used. Oh well. – sirdank – 2015-12-11T17:06:47.333

locked? This is to solve the particular error in the question, i.e. "the folder is open in another program." Is this your situation? – bcorso – 2015-12-11T17:39:26.387

1Solved the problem for me. – RubenGeert – 2016-04-24T08:27:31.607

FWIW, search may run for quite some time before finding results (minutes in my case). – Cedric Reichenbach – 2018-01-02T09:42:35.237

9

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

Joe

Posted 2009-07-15T17:15:04.147

Reputation: 91

lockhunter found the locking process for me that both ProcExp and ResMon could not find. – CleverPatrick – 2018-01-24T14:17:42.610

2Unlocker comes for 64-bit system. – avirk – 2013-04-14T01:58:04.840

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.

Brant Bobby

Posted 2009-07-15T17:15:04.147

Reputation: 2 186

Way good article. Important read. – Pacerier – 2015-06-08T20:17:58.877

6

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\""

Robert Collier

Posted 2009-07-15T17:15:04.147

Reputation: 679

Why not just use the UI version ProcessExplorer? – Pacerier – 2015-06-08T20:19:28.097

5

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

kpoehls

Posted 2009-07-15T17:15:04.147

Reputation: 766

@Wbdvlpr, @ kpoehls, Why would this work? I think it's just a myth and you happen to be lucky. – Pacerier – 2015-06-08T20:20:24.170

Yes - it worked for me! – TigerTiger – 2013-01-21T13:04:15.653

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.

None

Posted 2009-07-15T17:15:04.147

Reputation:

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

Posted 2009-07-15T17:15:04.147

Reputation: 854

2

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

Posted 2009-07-15T17:15:04.147

Reputation: 1 151

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

Posted 2009-07-15T17:15:04.147

Reputation: 63 242

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

Hector

Posted 2009-07-15T17:15:04.147

Reputation: 11

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

Posted 2009-07-15T17:15:04.147

Reputation: 11

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

Syed Mazhar

Posted 2009-07-15T17:15:04.147

Reputation: 1

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.

rubynorails

Posted 2009-07-15T17:15:04.147

Reputation: 254

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!)

johan

Posted 2009-07-15T17:15:04.147

Reputation: 1

0

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.

cruising by

Posted 2009-07-15T17:15:04.147

Reputation: 11

Why would IE lock local files and why .txt? – gronostaj – 2013-08-25T14:06:57.027

-1

  1. Find the file that you want to delete.

  2. Rename it to anything you like.

  3. Delete it.

Janpierre

Posted 2009-07-15T17:15:04.147

Reputation: 11

2This answer will not work. If a file or directory is use you can't rename it. – DavidPostill – 2016-04-02T06:49:43.703

-2

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.

samer sarrouh

Posted 2009-07-15T17:15:04.147

Reputation: 11