Ask Leo!

Why can't I delete this file?

Home » Windows » Windows Oddities

Summary: Sometimes a file cannot be deleted because it has invalid characters in its filename. There are techniques and tools to force the delete anyway.

Why can't I delete this file?

It's a fact that you can create files in Windows that are almost impossible to delete using normal methods. Typically it's the result of a hidden character in the filename - a character that for various reasons can't be seen and is difficult if not impossible to type. And yet if you don't specify the correct filename including that odd character you can't delete the file.

I can hear you asking "great, how did that character get there and more importantly how can I delete the file?"

The answer to the first part is speculation but I was recently pointed at a tool that will help with the second.

The biggest issue with invalid names is that not all programs filter out invalid characters from filenames before they pass them on to the system. For example, let's say you happened to accidentally hit the spacebar after the filename when you went to save a file. If the application you're using is not smart enough to strip trailing spaces then it may well create the file with a trailing space. You may think and see "FOO.DOC", but Windows sees "FOO.DOC ". A subtle, but important difference.

What's worse is when you attempt to rename the file or delete the file using a utility that then "does the right thing", it strips trailing spaces before it attempts to operate on the file. You type in or select "FOO.DOC " with a space and the utility takes it as "FOO.DOC" without a space, tries to delete it, and fails because that's not the name of the file!

There are actually several scenarios that can result in files that seem almost impossible to delete. Fortunately they are rare but they do happen.

What to do?

If your file system is FAT or FAT32 or most instances of NTFS you can use the old DOS "shortname". In the days before Windows filenames under MS-DOS could only be 11 characters long. For compatibility with old programs that relied on the 11 character limitation Windows creates a unique "shortname" for every long file name. For example, if your file is named "thisisalongfilename.isntit" a DIR /X in a command shell may show the shortname as "THISIS~1.ISN". It refers to the same file so you can delete using the shortname.

In some cases using the command shell or using shortnames isn't an option. That's a situation I found myself in some time ago. My disks are formatted with NTFS, and I've explicitly turned off "shortnames" for a little bit more speed. I had no way to delete the file I'd somehow created.

I was recently pointed at delinvfile, short for Delete Invalid File, from Assistance & Resources for Computing, Inc. It's a free Windows program that uses standard controls for drives, folders, and files to navigate to the folder and to select the file to be deleted. Push a button and it's gone.

It just got added to my little arsenal of handy tools I carry with me wherever I go.

Article 165 | Posted March 15, 2004

Recent Comments

err, yer! This software does jack for my problem. It doesn't find the problem file at all. I can't delete a file using ANYTHING so far. Five programs in and still got it sitting there in My docs folder. THIS PROGRAM NOT GOOD FOR ME THEN!!!!!

Posted by: marctowler at March 4, 2008 03:51 PM

I’ve been using the following tool that resolves the problem with trailing spaces or other unsupported characters in filenames. It is not free, but comes with samples and working code. It saved so much of my time!

http://www.abtollc.com/products.aspx

Posted by: Roger111 at March 24, 2008 03:50 AM

Finally! Those two folders have been sitting on my desktop for a few months and I can finally get rid of them! Thank you!

Posted by: Gan at June 17, 2008 07:43 AM

Malewarebytes [free anti-spyware from the usual download repositories] has a 'FileASSASSIN'- which would work well here. In fact, I'm mid way through clearing up a dozen such uncooperative files. Thanks for your leads too. What on earth crawled up those people who posted above? Phew! You'd think you told them to invest in SubPrime.

Keep up the good work, Leo.

R

Posted by: Rich at June 22, 2008 10:19 AM

Thanks, but how to make the different way ? imean I want make some autorun at usb flasdisk wich is can't be delete or even format it.

Could you help me to give some advice

Thanks

Posted by: feri at June 26, 2008 08:49 PM

Thanks for the infomation, should update your info, program is not free, (DelinvFile) Hate to spend that much to delete just one file. Some good info on your site.

Posted by: Larry at July 15, 2008 09:13 AM

After alot of pain this worked for me for a file on a CD with a trailing space.
1. dir /x
2. Find short filename for messed up file, Ex. "PLATT~92.QXD"
3. xcopy PLATT~92.QXD c:\quark\test.qxd /N
4. Now the file is on your drive with a valid name that you can change to what you need.

Hope this helps someone.

Posted by: Brandon at August 12, 2008 10:01 AM

Ok people,
wanna share with you how i got rid
of that stubborn obnoxious piece a crap.
The stubborn file i had was ones with :

^**@%@%#$^$#&#$&#$^%@%!@!$ crap like that
and they were more than 200 characters long.

I know how annoying and frustrating it is to have that
crap sit there like a statue, when you want it gone. Tried for
close to 8 weeks figuring out ways to remove this thing,
tried everything on the web not just google,
yahoo, msn literally EVERYTHING.Actually i'm not
too sure if reformating works , but i didnt reformat
because had too many files backedup and had
no place for extra storage.However none of the above methods,
worked.All the information in the forums
like using the commands to delete,renaming,delinvfile or any other
things didnt work for me.Infact i know how troubling
this is , i wanted to help everyone out there.

Here's what to do:
1)download unlocker : http://ccollomb.free.fr/unlocker/
unlike the other softwares i tried, this virus free software
is FREE and most importantly IT DELETES THE CRAP.

2)After installation, right click on the file you wanna delete
press unlocker,and when it launches, there's a small tab at the lower
left of the menu, which allows you to choose delete.
Click delete.
It will say file cannot be deleted, system has to restart to delete the file.
What it actually means is that file wont be deleted on the spot,
you need to restart in order for it to be gone, SO DONT REMOVE UR HARDDISK!!

3)When you're about to restart DONT REMOVE YOUR EXTERNAL HARDDISK,
DONT END ANYTHING, LET THE COMPUTER DO IT'S THING, JUST
RESTART UPON DELETING THE FILE FROM UNLOCKER,

4)Check if the file's deleted upon restarting
ONLY AFTER EVERYTHING'S DONE PROPERLY, AND FILE'S DELETED, REMOVE UR HARDDISK SAFELY!

5)Enjoy and heave a sigh of relief :P

Hope this helps someone :), all the best!!

Oh and by the way unlocker helps alot in terms of
like say you have trouble removing your external harddisk.
Say if you're in a hurry and need to catch a bus, but your harddisk just
cant be safely removed, unlocker
helps you to close all programs, just unlock all, or kill all processes.
Follow the same procedure, at my computer, right click on the drive you wanna end safely,
and then click unlocker. Then just unlock all or kill all processes.

That would come handy after you have disabled this 2 functions
that maybe allowing explorer to access all your external harddisk
files thereby preventing safe removal.

GO TO CONTROL PANEL:

1)Under classic view, go to back up and restore,
Click create a restore point at the left hand corner,
uncheck all the boxes under available disks and click
ok/apply.

2)Under classic view, click indexing options, then,
modify, than check if all boxes are unchecked.

With that said, next time when you wanna remove your
harddisk safely, also not forget to make sure you have all the
windows closed, and you're facing only your desktop.


Oh yea and by the way if it works, you can thank me at [email address removed] :):) ciao!!

Regards,
Shameer G.D.

Posted by: Shameer G.D. at August 22, 2008 11:01 AM

NICE!
Worked like a charm.

Posted by: Julian Lockhart at August 26, 2008 10:49 PM

Unlocker worked like a treat!! Tried lots of other methods over a few weeks but unlocker did it! Thanks Shameer!!

Posted by: Michael at September 6, 2008 07:06 PM

Post a comment on "Why can't I delete this file?":






(Email Address will not be published.)

Remember Me?

By popular demand...
my tip jar
Cuppa Joe
Buy Leo a Latte!

(you may use HTML tags for style)

New!

RSS feed Subscribe to the RSS Feed specifically for comments on this article.

Before commenting, please...

Please wait. Your comment is being processed ...


Ask Your Question:


ask-leo.com
Web

Archives

By Category
By Date

Advertisers

Advertise on Ask Leo!

««   »»

Question? - Ask Leo!
Who is Leo?
Link to Leo!

Terms, Conditions & Privacy