How to delete files and folders that cannot be deleted?

28

11

I have a backup copy of a previous Windows' Documents and Settings folder which only contains my original user and within 2 more directories: Favorites and Local Settings.

When I try to delete Local Settings I get this error:

alt text

When I try to delete Favorites, I get this error:

alt text

I ran this in a cmd shell:

attrib *.* -r -a -s -h /s

...but it did not help, nor did it return any errors/warnings.

I used Unlocker v1.8.5 and LockHunter repeatedly at multiple levels to see if any files are in use, but both always say: No Files Locked.

Update #1:

I was able to rename the directory, which now gives me this warning before (trying to) delete:

alt text

If I press Yes (or Yes to All) then I get this error:

alt text

Update #2:

I let chkdsk /f run which required a reboot since it's on my primary system partition. During Stage 2 scanning, I received about 40 of these:

Deleting an index entry from index $0 of file 25.

...followed by:

Deleting index entry cookies in index $I30 of file 37576.

...but I still get the first error dialog above when trying to delete.

I ran chkdsk again, this time: chkdsk /f /r. Produced no messages. Same result when deleting.

Update #3:

Digging deeper, the 99 is the name of one of many directories located deep in here:

C:\Documents and Settings.OLD\User\Local Settings\Application Data\Microsoft\Messenger\address@hotmail.com\SharingMetadata\user@hotmail.com\DFSR\Staging\CS{D4E4AE55-B5E2-F03B-5189-6C4DA6E41788}\

Inside each of those directories were files with names such as:

2300-{C93D01AC-0739-4FD9-88C7-13D2F21A208E}-v2300-{C93D01AC-0739-4FD9-88C7-13D2F21A208E}-v2300-Downloaded.frx

I noticed that, unlike all the directories, I couldn't rename any of these files. I also noticed that the file + dir names were extremely long:

Original directory = 194 characters
Filenames = 100+ characters
Together the length exceeds the 255-char limit which is bad and would explain the error message I posted in Update #1.

Partial Solution:

Rename all directories until the total path length is less than 100. Afterwards I was able to rename the .frx files, not to mention delete everything inside the Local Settings directory.

This is only a partial solution because these (empty) directories are still not deleteable,

C:\1\2\Favorites\Wien\What To Do..
C:\1\2\Favorites\Photography\FIRE

Same error as above:

alt text

Here is what Explorer properties shows for both folders:

alt text

Update #4 (another partial solution):

Using harrymc's answer combined with thoroughly reading through this amazing MS-KB article which contains nearly everyone's idea and then some, inconspicuously titled: You cannot delete a file or a folder on an NTFS file system volume.

I was able to delete the 2nd folder C:\1\2\Favorites\Photography\FIRE - the problem being that there was an invisible trailing space at the end. I got lucky when I did an auto-complete whilst playing around with the del "\\?\<path>" command which he suggested.

NOTE: A normal del did NOT work, nor did deleting from explorer.

Now all that is left is the first directory C:\1\2\Favorites\Wien\What To Do.. (yes I tried endlessly with multiple combinations of the above solution ;)

glenneroo

Posted 2011-01-05T20:49:15.890

Reputation: 1 800

@glenneroo try using LockHunter instead of Unlocker and see what it says. Also, what happens when you click "Yes" or "Yes to All" in the "Confirm File Delete" box? – ubiquibacon – 2011-01-05T21:17:40.580

LockHunter also says no processes are locking this file or folder. – glenneroo – 2011-01-06T03:25:23.020

I had a similar problem as you with some Adobe files buried deep in some folders from a backed up windows install. I tried renaming all the folders to 'x' to shorten the path, but it didn't work. I left them that way to remind me they weren't anything and let them sit there for a couple years until I finally DBANed the disc before sending it off to someone. – Tofystedeth – 2011-01-06T20:34:29.847

Regarding you 'Partial Solution': You have two empty, pretty short-named, folders left now that you cannot delete? Is this correct? You should post what error you are getting now. – Martin – 2011-01-18T15:36:03.783

Yes and yes. Updated. – glenneroo – 2011-01-18T15:51:50.340

1Because of the extremely little file properties you see (not even dates), I am thinking this is file pointer that points to a file that does not exists. I don't know how to fix this though, but this might give an idea to someone that knows... – awe – 2011-01-18T19:14:51.647

Ever considered swapping the drive? Sounds a bit like it's going bad or something. Maybe check the S.M.A.R.T. readings or something? – Svish – 2011-01-19T08:05:39.570

1

Just because there are some dead files that aren't even using up much space? The drive is ~2 years old and I'd rather not have to re-install again. As for SMART readings, Google released a report here that basically said you can't put too much weight on most of those readings: http://labs.google.com/papers/disk_failures.pdf Also chkdsk /R reported nothing wrong. Can you recommend a tool for Windows as an answer?

– glenneroo – 2011-01-19T08:09:39.953

@awe: Windows doesn't use the concept of file pointers internally. HarryMC's answer should do the trick.

– Billy ONeal – 2011-01-20T03:03:41.957

@glenneroo: Don't tell me that the problem is still not solved ! – harrymc – 2011-01-29T07:52:07.703

Wish it were otherwise. Read the updates - still one directory left! – glenneroo – 2011-01-29T11:56:57.710

Answers

29

del is for deleting files, rd aka rmdir is for deleting folders, so...

rd /s "\\?\C:\1\2\Favorites\Wien\What To Do.."

...should do the job! :-)

The /s parameter

removes all directories and files in the specified directory in addition to the directory itself.
Used to remove a directory tree.


If this doesn't work; even not with wildcards/auto-completion; then you have corruption issues.

Tamara Wijsman

Posted 2011-01-05T20:49:15.890

Reputation: 54 163

oh man that looks like it could be the answer right there :-) – James T – 2011-01-29T08:37:36.013

Wow amazing someone finally got it! You win a double-bonus! :) – glenneroo – 2011-01-29T22:49:23.767

@glenneroo: Have upvoted everyone that helped towards this as a return. :-) – Tamara Wijsman – 2011-01-29T22:53:08.160

6

You very likely have FS(filesystem) corruption. Run a chkdsk then attempt to remove the files.

Also make sure nothing is in use within the directory as the warning suggests.

I would also recommend making a backup of your important files before anything.

Jeff F.

Posted 2011-01-05T20:49:15.890

Reputation: 4 293

I used the tool Unlocker to verify no handles were open on any of those files. – glenneroo – 2011-01-05T21:02:56.820

That's what I figured. You probably need to run chkdsk /f – Jeff F. – 2011-01-05T21:05:39.047

Didn't help. See update #2 in my question. – glenneroo – 2011-01-05T22:05:06.977

Back up your data, it is never good when you get a slew of deleted index entries on a chkdsk. Usually means a failing hard drive or failing file system that chkdsk cannot save. – Moab – 2011-01-05T22:29:02.920

Really? I regularly get those after a BSOD during a write operation. I'm assuming these happened from one of the last BSODs (they happen every few months). – glenneroo – 2011-01-05T22:42:02.047

1@Moab: No, the index cleanup with chkdsk is normal. It's an artifact of how they're stored, they can only be cleaned up during a disk check. I can't remember where I read that though. – afrazier – 2011-01-05T23:52:08.630

1@glennroo - bsod's during write operations are signs of failing disk, too. I wouldn't be surprised to see your disk last another year, but I also wouldn't be surprised to see it die tomorrow. – Joel Coehoorn – 2011-01-06T01:48:07.480

Agreed with the first part, but if you've ever used a tool to watch drive I/O you'd be surprised how few milliseconds occur between writes. IMO the BSOD error code will (hopefully) be more valuable. My own BSOD error codes usually pointed to the GFX driver or my firewall, however, since re-installing (and using different drivers/firewall) I haven't had any BSODs. – glenneroo – 2011-01-06T03:19:06.610

1I see that you have trid chkdsk /F; try also chkdsk /R which performs 2 additional steps to attempt to mark bad sectors and recover data. – AniDev – 2011-01-18T17:11:41.573

@AniDev: Ran it but no messages. Deleting still a no-go. – glenneroo – 2011-01-19T07:23:29.477

Chkdsk /r does a sector check and marks bad sectors, typically, it does not fix this kind of issue, though I suppose it's possible. – Jeff F. – 2011-01-19T14:19:44.723

6

I would try running chkdsk first as Jeff suggested. If this does not work, you could boot up with a linux live cd, mount the hard drive and delete the folders from within the linux live environment.

byachna

Posted 2011-01-05T20:49:15.890

Reputation: 618

I'm extremely hesitant to use an alternative (to the closed-source NTFS) to delete files from a NTFS partition. From my experiences, read support usually works fine but writing can be dangerous. – glenneroo – 2011-01-05T21:02:11.810

1write support on NTFS is now very good on modern linux distros, especially considering even WinXP does not completely implement the NTFS spec. – Jonathan – 2011-01-05T21:14:44.217

1Agreed, Linux has excellent NTFS Support. – Jeff F. – 2011-01-05T21:59:20.320

Not long ago (Summer of 2010) I used ntfs-3g to delete files before re-installing XP. Afterwards during XP installation, chkdsk found a metric shedload of corrupt files. I've also managed to kill ntfs drivers in the past just doing reads. Granted both cases were on extremely fragmented partitions with several 100,000 files. – glenneroo – 2011-01-05T22:14:22.853

5

I still receive the Error 99 dialog above when trying to delete.

99 isn't an error number — it's the name of a file or folder inside the folder you want to remove. Look for this item.

Once you find it, it's just complaining about a permissions error. This is likely because certain things in users' profiles folders are set up to only have permissions for that user and no one else, and are set not to inherit permissions from their parent, or for some other reason all permissions on the file were lost. The result is that no user account on your computer has the ability to do anything with the file or folder.

To fix this, right click on the file (or it's containing folder to ensure you get everything), choose Properties from the context menu and then the Security tab in the dialog that opens. This screen will have an Advanced button that you should click. Look for the Owner tab on the dialog the opens. You should now be able to use this window to take ownership, which will assign new permissions entries to the item and finally allow you to delete it.

Joel Coehoorn

Posted 2011-01-05T20:49:15.890

Reputation: 26 787

Good point about the filename! Setting permissions didn't help, but incidentally I found half the answer! – glenneroo – 2011-01-06T02:54:05.857

5

The following I have read on Microsoft's support site:

1) use dir /x to get the short names (8.3 notation) of files / folders listed 2) use rmdir /s shortname to remove a folder whose long name is non-standard

pt3

Posted 2011-01-05T20:49:15.890

Reputation: 51

Good idea! Unfortunately all the folders that I can't delete have no short name i.e. it's empty when I type dir /x :( – glenneroo – 2011-01-18T13:21:00.563

3

You may be able to use the Unicode \\?\ syntax in cmd to delete too-long directories, as the path-length with this syntax is "limited" to 32,767 characters :

del /s /f /q "\\?\C:\Documents and Settings.OLD\User\Local Settings\Application Data\Microsoft\Messenger\address@hotmail.com\SharingMetadata\user@hotmail.com\DFSR\Staging\CS{D4E4AE55-B5E2-F03B-5189-6C4DA6E41788}\"
rmdir "\\?\C:\Documents and Settings.OLD\User\Local Settings\Application Data\Microsoft\Messenger\address@hotmail.com\SharingMetadata\user@hotmail.com\DFSR\Staging\CS{D4E4AE55-B5E2-F03B-5189-6C4DA6E41788}\"

It might help to press the tab key to cycle through directory names once you get a \, so that Windows will start auto-completing the directories that exist under that folder.

See Microsoft's Naming Files, Paths, and Namespaces.

harrymc

Posted 2011-01-05T20:49:15.890

Reputation: 306 093

This will work, but I believe the del command has the MAX_PATH limit :( – Billy ONeal – 2011-01-20T03:00:05.767

Nice trick! I got around the long file names by renaming directories to 1-2 chars. I tried these commands on both remaining directories: Could not find file. followed by a The system cannot find the file specified. – glenneroo – 2011-01-20T05:52:57.827

Updated my answer. Using this version of del i was able to delete one of the two remaining offenders (which had a trailing space). Bounty is yours, but the plot thickens! – glenneroo – 2011-01-20T06:25:55.023

In ultra problematic cases, you might be able to delete instead the containing directory (after moving out the stuff you wish to keep). – harrymc – 2011-01-20T06:46:00.827

Very pleased, I've had a corrupt directory name for 3 years and finally found this! Using the rmdir command above allowed me to get rid of the broken dir. – hazymat – 2014-03-02T15:21:46.863

2

I personally agree with byachna and CarlF that a linux live cd is your best bet. Linux doesn't care about permissions so you can go in and delete stuff without it complaining. I've never had any issues with NTFS writing from linux. I've been doing it on a regular basis for several years.

I understand you don't want to mess with linux, so I'll suggest something else. Something that Ashimema already suggested... but forgot a few links. Instead of a linux live cd, you can try one of the many windows live cd's.

http://www.ubcd4win.com/ (requires xp install cd to create)

http://www.reatogo.de/REATOGO.htm (requires xp install cd to create)

http://www.nu2.nu/pebuilder/ (requires xp install cd to create)

http://www.vistape.net/index.php (requires vista install dvd to create)

Try booting up in whichever live cd you decide to use and delete the folders that are causing all the problems. Since it is windows, it will enforce file permissions. You might have to change the permissions or ownership of the files in order to delete them. Perhapse even try the "\?\" trick from the live windows cd.

Another thing to try would be the cacls or icacls command to see if you can give yourself permissions on the folders.

James T

Posted 2011-01-05T20:49:15.890

Reputation: 8 515

Will give them a try and report back (when I have a couple hours). – glenneroo – 2011-01-29T11:59:06.630

0

Boot your system using an NTFS-aware Linux distro, say an Ubuntu liveCD.

Mount the Windows file system.

Delete whatever you want, since Windows won't be able to say "No."

BEFORE DOING THIS MAKE A FULL BACKUP.

CarlF

Posted 2011-01-05T20:49:15.890

Reputation: 8 576

1Thanks but byachna already suggested this. I hesitate to try because I've had problems in the past with corrupted filesystems. Also this case is dealing with corrupt files i.e. using an unsupported NTFS driver might just muck up my system completely. – glenneroo – 2011-01-18T17:16:39.617

The current NTFS drivers in Linux are actually less likely to corrupt filesystems than Windows, in my limited experience. – CarlF – 2011-01-19T18:45:17.943

3I'd really really like to see data to back up that statement. I've never had Windows corrupt a FS except for failing hardware. – Billy ONeal – 2011-01-20T02:59:39.807

There's a reason I wrote "in my limited experience". I've had a couple problems like glenneroo's using Windows (XP and Vista) and none with NTFS-3G. I thought the disclaimer would make that clear. – CarlF – 2011-01-20T13:39:46.973

0

There are a number of convoluted and difficult ways to solve this as I've found out in the past.

Now that i'm confident with what i'm doing, I'de simply run a chkdsk, then boot up a live cd to delete the files if there was still a problem (if your worried about linux's abilities with ntfs, then try out either BartPE or [Windows PE][2], both freely available)

If your going for the long way round, all the other suggestions will certainly help you whittle down the actual error.

Ashimema

Posted 2011-01-05T20:49:15.890

Reputation: 145

Cheers James for adding the links I could not (being too new here) in a post below! – Ashimema – 2011-01-29T15:11:47.857

0

Late to the party but this method works most of the time, if not boot from a linux distro and delete from there.

Open an elevated Command Prompt window and leave it open.

Close all open programs.

Click Start, Run and enter TASKMGR.EXE Go to the Processes tab and End Process on "Explorer.exe" Leave Task Manager open.

Go back to the Command Prompt window and change to the directory the AVI (or other undeletable file) is located in. At the command prompt type DEL < full path to the file you wish to delete>, or whatever command you desire.

Go back to Task Manager, click File, New Task and enter EXPLORER.EXE to restart the GUI shell. Close Task Manager.

Moab

Posted 2011-01-05T20:49:15.890

Reputation: 54 203

-1

Joel's answer is half right, you need to activate the security tab first, go to control panel > folders options and the second tab(i forgot its name) in the end of the list with options there is something about advanced folder management(again i don't know whats the name in english) once you do that you can then set permisions for your user in the security tab as mentioned before.

Guillermo Siliceo Trueba

Posted 2011-01-05T20:49:15.890

Reputation: 846

I already had those options enabled, plus I already tried what he recommended but it didn't help. Read Update #3 and Partial Solution for what is happening. The folder that I can't delete doesn't even have any properties, much less security options. – glenneroo – 2011-01-06T03:22:56.607

Make sure you add full access and options to the user EVERYONE, with the user verifier included you can do this. – Guillermo Siliceo Trueba – 2011-01-06T03:28:04.187