Cannot delete file or folder

Tue, 2007-07-17 11:46 by admin · Forum/category:

This article describes different methods to delete files or folders that cannot be deleted normally.

After trying the following methods, please click here to let us all know your results.

Table of contents

for this article


Reboot, then delete.


Open a command line window (WindowsKey + R, enter: cmd). Move to the folder in question by means of CD commands like CD \ and CD foldername.

Delete the file or folder by using the DEL command to delete files or the RMDIR (remove directory) command to remove directories (folders).

Kill explorer.exe

If this, on its own, is still not enough, then leave the command line window on the desktop, open Task Manager (Ctrl + Shift + Esc), and kill all explorer.exe tasks. Your desktop will go blank, except for the windows already open.

Now try to delete the offending file by means of the DEL command, or folder by means of the RMDIR (remove directory) command, in the command line window, as described above.

After that, in the command line window enter:


to restart your desktop. If you closed the command line window, you can still restart explorer by opening the Task Manager by holding down the Ctrl and Shift keys and briefly pressing the Esc key. In Task Manager select Applications, New Task and enter: explorer

Log off

If the previous method fails, particularly with multimedia files, log off, then log on again, but do not select the file in Windows Explorer. The safest way is not to open Windows Explorer in the first place.

Then try the previous method again.

Reboot again

An even stronger measure would be to reboot, then try the previous methods again. This would work, for example, if a service has the file open.

Delete containing folder

[Thanks to John Barrington:] If you can't delete a problem file, try deleting the folder that contains the problem file. If this doesn't work, try this next item.

If the problem file and its folder, we'll call (A), is within another folder, we'll call (B), try to delete the folder (B) along with any troublesome contents.

Of course, you want to make sure, if you have any other important files or folders within either folder, that they are saved in another location first.

Use RMDIR on containing folder

Begin like the previous method, but try also

rmdir /s foldername

(replace foldernamewith the name of the folder to be deleted). This command should delete a folder with all its subfolders.

If the folder name contains one or more spaces, enclose it in quotes. Example:

rmdir /s "folder name"

Note that the abbreviated command rd can be used in place of rmdir.

Use short name

If the folder name contains strange characters, use a command line window again, but use the DIR /X command to find the short name (for example: PROGRA~1) and use the short name instead. The short name is DOS compatible and has no more than 8 characters for the main name, a period, then no more than 3 characters for the extension.

Retry the previous methods that use a command line window, but use the short name now.

Note: Sometimes an illegal file name can cause Windows Explorer to use nearly 100% of the CPU time.

[Thanks to astk1:] Sometimes the abbreviated name can have a number other than one and can have an extension. If the above does not work, proceed as follows.

  1. Open a command line window (Start, Run, type: cmd, press the return/enter key).
  2. Navigate to the folder using "cd .." and "cd pathname", where pathname is the name of the next subfolder you want to go into.
  3. Type dir /x to see the actual real short name of the subdirectory. Critically: This may include an extension, e.g. "ABDCEF~1.XYZ".
  4. Type "rmdir /s", replacing the example name with your actual folder name.

Safe mode

Boot into safe mode and try to delete the file or folder there.

Stop program

If you're trying to delete a program file, like one with the extension .exe, the cause could be that the program is currently running. Stop it, then delete the file.

If the program starts automatically, check the article Autorun causes on how to remove the start command. Do it, reboot, then delete the file.

Rename or move during next boot

If this also doesn't work, there is a way to rename or move a file or folder during the boot process. For this you need to use the registry editor REGEDIT.EXE. See the Registry warning for a general warning.

Create a multi-text value in

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\

named PendingFileRenameOperations of type REG_MULTI_SZ. In pre-XP Windows versions you have to use REGEDT32.EXE to create this value type.

The first line of each pair is the current file or folder path and name with \??\ in front of it.

The second line of each pair is the new file or folder path and name with !\??\ in front of it.

Example for one pair which moves the file mfc42.dll from the temp folder to the system32 folder and overwrites any existing file at the destination:


You can add as many pairs as you like. The move operation is performed directly after the next reboot. You can also give folder paths, so the folder will be renamed. But both paths have to be local.

There is a Windows API call for this, named MoveFileEx, and somebody in Germany has even written a utility named MoveEx for it. You can download it from Use it if you need this function often. A Posix utility from a Windows Resource Kit named mv.exe also does it, just in case you still have the resource kit around.

Use another operating system

Boot into another operating system to delete the file from there. The other operating system can be, for example, another installation of Windows, BartPE, Knoppix, Ubuntu, or any operating system that can read the file system used (NTFS or FAT32).

Connect hard disk to other computer

Remove the hard disk from the computer and connect it to another computer. Delete the files or folders there.

Use unlock utility

If you cannot delete a file or folder because it is in use, you can use one of the mostly free utilities, such as Unlocker.

Internet Explorer 8 issues a warning when you open that page, but as far as I can tell (I checked the code of the page at least superficially in March 2010) that is a false alarm.

Shorten names

If the cause is that the path and file name is too long, first try to rename folders in the path with shorter names.

If that doesn't work, you can use the following method, reported 2007-05-17 by Mark Briody:

Open a command line window and use the subst command to create a virtual drive to the folder containing the long file name, e.g. (all in one line):

subst x: "C:\Documents and Settings\briodym\Favorites\Mark\Gadgets and Hardware\Hardware\Stores\eBuyer"

Then change to the virtual drive x:, and you should be able to delete, rename, and move files and folders.

Finally, to clean up, remove the subst again with:

subst x: /d

Deal with hidden or system files

[Thanks to warpcoil, who first described this method in a comment below]

This method deals with files that carry the hidden or system attribute. You can delete such files in Windows Explorer, if you set the folder options such that these files are shown in the first place, but the following method can delete them from a command line window.

Open a command line window and navigate to the offending folder by means of the cd command.

Show all files, using the attrib command. Note the attributes displayed as single letters on the left side of the listing:

Letter  Attribute
R Read-only
H Hidden
S System

Delete the offending files with the commands:

del /f /a:s

del /f /a:h

Replace with the name of the offending file or files. You can use wildcard characters. For example, the following command:

del abc*.* /f /a:h

would delete all files whose names begin with abc and which carry the hidden attribute, regardless of the system or read-only attributes.

When it works you get no response, but typing attrib again will show that the file has gone.

Access rights

aguggis wrote an excellent comment, outlining the following procedure for the common case that you do not have sufficient access rights to delete a folder or file. Thanks!

I was unable to access or delete a folder created by rsync on Windows XP, and none of the solutions proposed here worked. The simple but effective solution [meanwhile slightly enhanced] was the following:

  1. Right click on the problem folder --> Properties.
  2. Select the Security Tab. (See below for Windows XP Home.)
  3. If necessary, click on Advanced, Owner, and take ownership.
  4. Mark your username and authorize full control.
  5. Apply and OK.
  6. Now you can delete the folder without problems.

This procedure can be used to delete the System Volume Information folders that Windows creates automatically.

In Windows XP Home Edition there is no "Security" tab, but if you boot your computer into safe mode and log on as Administrator, you will get the "Security" tab. For some more details, please have a look at:

How to take ownership of a file or a folder in Windows XP

Endlessly recursive folders

A very special case occurs occasionally when a program creates an endlessly recursive folder structure, where new folders are always automatically created until Windows hits the path name length limit. You could also call this an endless folder chain, where each folder contains another one, seemingly ad infinitum, were it not for the path length limit.

The case does not seem to be well-researched, but there is at least one working solution.

The idea is to move the tree, beginning with the second level, to the first level, delete the orphaned original first-level folder, and keep repeating this operating quickly through a batch file, until all folders are gone.

Since you cannot move a folder next to a folder of the same name, you first have to rename the top-level folder to just any other name.

Let us assume that you have a folder structure like this:


Then the following batch file, sitting next to the topmost x folder, will remove all folders. Open a text editor and type in the following:

ren x y
move y\x .
rd /s /q y
goto loop

Do not overlook the dot at the end of the third line and the space to the left of it.

Replace x in the above batch file with the actual name of your repeating folder. Leave y in place.

Save the batch file and give it a suitable name, for example delete.bat .

Put the batch file next to the topmost offending folder and run it like this:

  1. Open a command line window in the folder where the uppermost problem folder and your batch file are.
  2. Type in the name of the batch file.
  3. Press return.

After 30 s interrupt the fast-running batch process by pressing Ctrl + C. It should have endlessly issued folder-not-found error messages after all folders have been deleted. Check whether the folders are all gone.

If not, you may have a very slow computer or a very slow graphics adapter or driver, so the batch file cannot keep up with Windows creating new folders. In that case restart the batch file, then minimize the command line window for 30 s, re-open it and stop the batch file.

If you have a more complicated folder structure like


then you have to change the batch file like this:

ren a y
move y\b\c\a .
rd /s /q y
goto loop


After trying the above methods, please click here to let us all know your results.

What happens when you try?

Thu, 2008-04-17 16:25 by admin

What's the exact error message you get when you try to delete these folders?

These three folders are exactly the ones that cannot be shared on Windows XP with Simple File Sharing enabled, like on XP Home.

My first guess is that you have no access rights to some folder or file in these three folders. The method to get around this is to take ownership of the folder first, then give yourself, or Everybody, full access rights. Then delete them.

Simpler method for deleting long file/folder name

Mon, 2007-12-31 19:39 by ddx (not verified)

I had this problem with long file name, just couldnt delete the folder. The solution is quite simple, you can just 'rename' folders to shorten its/their names and then delete! Just do it in Explorer, shorten each folders name until you can open up last folder, then delete!

Sometimes folder name too long itself

Thu, 2008-02-07 05:25 by astk1

Just thought it might be handy to make it really clear about short and long names. I had a folder with a really really long name (eg "Dorothy and Julie blah, blah, blah and so on and more blah, blah etc" that came about because of Nokia PC Suite syncing, and the folder contained a music file. Windows XP/Explorer wouldn't allow me to do anything with the folder - couldn't open, move, delete, or rename, couldn't delete within command window (cmd.exe) using del doroth~1 as seemed to be suggested in various forums. Here's how:
open command window (start, run, type cmd, press enter)
navigate to folder using "cd.." and "cd pathname" etc
type dir/x to see the actual real short name of the subdirectory AND CRITICALLY this may include an extension eg. "DOROTH~1.STR"
then type "cd doroth~1.str" (that is, whatever your short folder name is)
then delete the files in the directory (say, del *.* or use the short names trick again if necessary)
then cd.. to get back into the parent directory
then "rmdir doroth~1.str" to remove the empty subdirectory/folder

Thanks a lot!

Thu, 2008-02-07 09:29 by admin

Thanks for your good explanation! I have already incorporated it into method 8 above with an attribution to you.

As an early contributor you now also have your own blog on this web site. Please have a look at the "Blogger" forum for details.

Thanks, good hint!

Mon, 2007-12-31 20:46 by admin

Yes, it seems obvious, but sometimes the easiest things are overlooked.

Your hint has been incorporated in the main article, method 15.

The easiest way I found is

Tue, 2008-03-25 14:20 by NoireX

The easiest way I found is to download the programm "Unlocker" which simply deletes every reference to a folder. It also offers the possibility to delete the folder or document at the same time.

Yes, that's method 14

Tue, 2008-03-25 14:52 by admin

I also have Unlocker installed. It is a fine program and makes it easy to delete any recalcitrant stuff.

Recommended for everyone who has this problem more often.

sorry, i posted my post in the wrong area

Wed, 2008-04-16 17:19 by Pangaea

hi, im the guy that posted the farily lengthy post (at the top) regarding the 3 undeletable folders ive been having great trouble dealing with ..

Im not sure why it was posted up there, but its the most recent post in this thread.

I refare to the post subject "PLEASE FOR THE LOVE OF GOD"

one click gone/partition and gone

Wed, 2010-03-17 03:03 by Wedge1967

Hi I had a problem with 2 folders that were left when I removed Adobe lightroom, could not delete them at all.
you can try downloading tuneup utilities 2010, it has a file shredder that works real well, but best of all once I ran "Tuneup-1 click maintenance" it picked up the 2 files as droken shortcuts and removed them no problem,
the Free edition is only for 30 days but you might like it, I did and decide to get the licence,
it realy does keep my laptop running smoothly, and the price is not too bad for what you get.
You can also try for more help
alternatively if you have a windows disc, boot from the disc and create a second partition say of 1 to 2 GB's exit the setup without installing windows by pressing the Esc key
now startup your PC like normal, once the startup is completed go to my Computer(XP)/Computer(Vista) to find the new partition, it will show up as a second drive, move the files to this drive and format it.
once done boot from the disc again and delete the small partition, press Esc once it deleted, and restart you PC as normal
I used this method in XP a lot
you could also disconnect your master drive, set the slave as a master(only if its an older IDE drive) boot the computer with your XP disc and format the drive from there, just hit Esc before the windows installation starts to exit without installing
put you master drive back and Boot your PC as normal
The only reason I sugest removing the master dive is because you can format the wrong drive by mistake this way there is only one drive to worry about formatting (I tried formatting a slave drive once, lost everything by formatting the C: drive)
XP can be a little unclear about which drive is the primery one.

New comments at the top

Thu, 2008-04-17 16:21 by admin

When you add a new comment, rather than a reply, it appears at the top. This is intentional, nothing to worry about.

ROBOCOPY saved my day !!

Wed, 2009-04-15 11:21 by gonzalongo

Hello everybody,

I got to this page trying to find info on how to delete a rogue folder that could not be removed on my desktop. And your ideas enlighted me. I had a folder that could not be removed due to its depth or number of subfolders. I tried chkdsk, miniwinpe, vistawinpe, etc

Then I rememberd the robocopy /MIR command.
So I created a folder called test and place a hello.txt file on it, then from the cmd I ran
robocopy /MIR "d:\test" "D:\doc&settsetc\roguefolder"
It took about 7 minutes but I ended up with just the hello.txt that could we wiped on the spot.

Robocopy is built in on vista.
I was using winxp, so I downloaded from microsoft. It's part of the win2003 resorce kit I believe and I think it's free.


Yes, it's free

Wed, 2009-04-15 13:51 by admin

Yes, robocopy is free. It is also one of my favorite and most-often-used tools.

Thanks for ths good hint!

Robocopy with Win 7

Wed, 2009-09-16 16:49 by tblount

Windows 7 now includes Robocopy.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.