48

I try to delete an empty folder, but I can't because the windows dialog says it is used at the moment.

How can a empty folder be used?? How can I solve this, without having to restart the computer or log off?

  • 6
    Your going to need to restart your system to delete the folder. You will have to determine which process is preventing the deletion of the folder. – Ramhound Jun 21 '18 at 11:02
  • 29
    It's always worth a quick check to see if you have a shell (Cmd, Bash, etc) running with the folder as its current directory. This is the usual reason that an empty folder is flagged as in use. – AFH Jun 21 '18 at 12:04
  • 15
    <rant>The only real solution is to reboot. Ideally, into Linux as I did a few years ago. This solved the problem permanently.</rant> – maaartinus Jun 21 '18 at 21:01
  • 3
    IObit Unlocker: "Never Worry about 'Cannot Delete Files' on Your PC" ... or the equivalent. That answer sounds too much like work. – Mazura Jun 22 '18 at 0:53
  • 4
    Glad to know this is still an issue 8 years later – txtechhelp Jun 22 '18 at 6:58
78

You will need to use Microsoft's Process Explorer (just an exe): https://docs.microsoft.com/en-us/sysinternals/downloads/process-explorer

It will let you know which app is handling that folder and you will also be able to kill that handle.

Find -> Find handle -> search for folder's name (will take a while..)

Visual tutorial: enter image description here

  • 4
    Or use the handle.exe utility (also on the sysinternals site) for a command line solution. – ErikE Jun 21 '18 at 16:22
  • 10
    This absolutely works. Only drawback is: You find software running (as services) on your machine that are holding those handles for seemingly no good reason and it just leaves you frustrated that relatively useless stuff is so invasive and written so badly... (though once you think about it, it makes sense …) – davidbak Jun 21 '18 at 16:40
  • 3
    Alternatively, before going through all that, you might want to try rebooting and try again. If it is still locked, then something that gets launched at boot or log on time is grabbing it when it launches. – jpmc26 Jun 21 '18 at 17:35
  • 17
    Do note that forcing handles closed can cause data corruption in certain circumstances. Explorer should handle it fine, but many programs may not – Justin Krejcha Jun 21 '18 at 18:16
  • 4
    I'd recommend killing the process that owns the handle instead of closing the handle.. You should think twice either way... – Alec Istomin Jun 22 '18 at 17:26
13

I found another way. You can also solve it by restarting explorer.exe.

However this does not work if it is locked by another process other than explorer.exe.

  • 6
    This simple trick works for me most of the time. – NVZ Jun 21 '18 at 12:49
  • 34
    No. It will only solve the problem if the folder is locked by explorer. – Salman A Jun 21 '18 at 16:53
  • 6
    And your shell may not even be explorer.exe – Lightness Races in Orbit Jun 21 '18 at 20:26
12

Sysinternals suite has already been mentioned, but ProcessExplorer is actually the wrong tool. movefile is what you want. Killing the process that has the directory open may work, but it is not a good (or safe) approach.

With movefile you can, well... move files (directories are files!) on the next reboot. Moving a file to no destination, i.e. "" schedules deletion on next reboot. Note that it needs to be run from an elevated prompt (otherwise you get Error 5 trying to schedule boot-time deletes).

10

You can follow these steps to find which program is locking folder:

  1. Run following command on command prompt wmic process > processes.txt. This will create an output file processes.txt with details of all process running.
  2. Open file in processes.txt in a text editor.
  3. Search for locked folder name. You will get Name and PID or process accessing folder.
  4. Kill process using TaskManager or using command TaskKill /PID <pid>. Where <pid> is PID found at step #3.
  • I wish this worked. It didn't. CD C:\ - md temp - cd temp - md utemp - cd utemp - notepad - cd .. - rd utemp (failed due to notepad) - wmic process > processes.txt - the result ing processes.txt did not contain "utemp", – TOOGAM Jun 24 '18 at 9:18
  • @TOOGAM Thanks for pointing that out. I am surprised to see that it actually happened with Notepad. Tested Notepad++ too and was able to delete folder without any issue. +1 for accepted answer. – Sandeep Jun 24 '18 at 10:37
5

You can forcefully terminate the process responsible for "locking" folder given the process ID is known, and any good process killer can do that without having to restart the system.

Alternatively with a GUI you could use Iobit unlocker to unlock the folder, and thus delete the folder afterward. Drag the target folder on the iobit interface then, on the scrollbar beside select unlock and delete.

Sample screenshot

  • 1
    Disclaimer!! no affiliation to the software, but just happen to be an easy GUI based way to do it – xavier_fakerat Jun 21 '18 at 12:14
  • 3
    Using this software might cause the process that has the lock on the file/folder to crash or become unstable. I would suggest using datester's answer – Cfinley Jun 21 '18 at 17:13
  • 1
    Windows may reuse the handle for another file, which can lead to really nasty stuff: the application that locked the file will now unknowingly work on another file, which can potentially have disastrous effects. – gronostaj Jun 22 '18 at 8:42
  • 1
    Ok fair enough to those who insist this method is bad, but trust me it still gets the job done for me without even breaking a sweat. Besides there are just too many ways to "kill this cat" – xavier_fakerat Jun 22 '18 at 10:22
  • 1
    @xavier_fakerat You either didn't understand the problem that gronostaj lined out or you have a very cavalier attitude towards your files. – Voo Jun 23 '18 at 9:36
2

I also had this problem before, and I solved it by going to the Git Bash, and using rm -rf my-directory.

I have no idea why it worked tho, maybe Git bash has more right than the windows command.

If you don't know Git, you can download it by typping 'Git' on Google, install it and then just right click on your explorer, where the directory is, and click on 'Git bash here'.

  • I am using git bash, probably this was actually the cause. – Black Jun 25 '18 at 8:27
1

I've actually noticed in the past that even with hidden files on and all the bells and whistles saying to show all files that certain programs would still have files that if saved with them were completely invisible in explorer. That's likely the case here. What I would do is go into whatever programs you were using this folder with and go to open file (if applicable) and see what is actually in the file in that view. There might be a lot of junk windows seems intent on hiding from you.

0

I've had this problem before, years ago when I used a website's automatic convert/download to change a page's html into a txt file download. The way Windows deals with the naming of files made it so that the quotations in the title changed the filetype to whatever was after the quotes, and made it undeletable. The solution I found was also described as being able to delete folders, so it should help you too.

First, open command prompt with admin privileges. Say that the folder I want to delete is in C:\Users\XXXXXX\Downloads

Make sure to include spaces wherever I make them, or else it won't work

Type in the command:

cd /d C:\Users\XXXXXX\Downloads

Next type:

dir /x

That will show you a list of all items within Downloads, with the date/time created followed by a ( <DIR> ) if a folder / a ( 0 ) if a file, the name in a shortened format, and then the full name.

Find the shortened name of the folder you want to delete and then type it exactly as shown in the list - capitalized, numbers, tildes, whatever (without the labeling 0 if a file) - minus the brackets I include here in the example:

rmdir /q /s [SHORTNAMEHERE]

And that's it! If you want to delete a file, just change rmdir to erase, and you're good! Just make sure that the folder you want to delete is actually empty and has nothing important in it first.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.