Ask Leo! by Leo A. Notenboom

Why can't I delete this file?

Search First! Then browse: Categories | Full Archive | By Date | Newsletter
Ask Leo! on Facebook

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 C1907 - March 15, 2004

Was this article helpful? «Yes» «No»

Helpful? Get new articles weekly by email in my FREE newsletter!

Your Name:
Your Email:


Why Subscribe?

Recent Comments
115 Comments

I had a file on my computer that was most likely the result from a corrupted downloaded file which I could not delete (my system locked-up in the middle of a download and I had to restart the PC).
I tried changing it's name, tried changing its attributes (read only). I tried to delete it using command line but I kept on getting "File can not be found" messages even though Windows attributes showed it to be 15.7 MB, it seemed as if nothing would work.
Then I came upon someones suggestion to download Ubuntu (8.04) and burn the iso to cd and create a bootable CD version.
I did and then restarted my PC into Ubuntu and from there went to "places" and found the file I wanted to delete. I sent it to Ubuntu's trash and then emptied the trash and my problem was solved.
A simple and FREE solution to a frustrating problem.

Posted by: Eggy at March 21, 2010 5:31 AM

sir
i had a photo impact 12 i created a files with UFO extensions and know i cannot delete these files .... my computer's windows is win 7

when i tried to delete these files the delete process hanged then i see a window with three choices ... they are ( close window or keep working or .....)

what can i do ?
please somebody help me!!!

Posted by: ismo at April 5, 2010 7:39 AM

I have used Unlocker tool at [broken link removed] to delete files that was locked.

Posted by: Ronald D at April 22, 2010 12:10 PM

Leo and Co.

You can also use the "Process Explorer" from Sysinternals to kill the DLL/Handles. I had a Zip archive that refused to be deleted because the handle was frozen. I killed it, and away it went! All you have to do is search for it.

Posted by: Sean at May 25, 2010 10:50 PM

I remember a problem I had many many moons ago.
A game I played under DOS asked you to name your saves, and once just to see what happened, I named the save "ha ha ha".
This caused immense problems, because the game actually called the file that, and DOS would read as far as the first space, and stop.
So, DOS couldn't find the file. So the game couldn't find the file. And the file was undeletable (because DOS couldn't find it).

Posted by: Bob at July 16, 2010 4:39 AM

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



(Name will be included when your comment is published.)



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

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

Before commenting, please...

  • Read the article at the top of this page. If your comment shows you didn't, it'll be deleted and ignored.

  • Comment only on this article. Use the Google search box at the top of the page if you have a question about something else.

  • Don't include personal information in the comment. No email addresses. No phone numbers. No physical addresses.

  • Don't spam. Excessive links to unrelated sites within a comment or across multiple comments will cause all such comments to be removed.

  • Don't ask me to recover lost passwords or hacked accounts. I can't, and those comments will be deleted.

  • I can't respond to every comment. And I can't vouch for the accuracy of others who do.

Please wait. Your comment is being processed ...


Question? Ask Leo!