Ask Leo! by Leo A. Notenboom

Why can't I delete this file?

Search First! Then browse: Categories | Full Archive | By Date | Newsletter

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
110 Comments

My problem was that with my file buried about 15 folders deep the combination of these folders and the file name they combined exceeded the max file length. I just had to rename the folders to something short until I got under the max length and then I could erase that file.

Posted by: Ron Richardson at November 9, 2009 4:21 PM

Unlocker worked!! :D

Posted by: Haikal at November 10, 2009 4:24 AM

I have figured out that by corrupting the file it will delete. I corrupted the file by opening it in Notepad and then deleting some of the characters. I may not work with all files but it worked for me on a video file.

Posted by: Brian at November 11, 2009 10:40 PM

Sir,
In my laptop Operating system is windows XP.
When i change my operating system windows 7,i can't delete that Windows Xp file.
What I Do????

Depends on how you "change my operating system to Windows 7". A reformat and reinstall, my recommended approach, removes XP completely.
Leo
14-Dec-2009

Posted by: Dhruv at December 13, 2009 10:32 AM

Well Leo, a final comment at the end of this year (2009). It seems that your blog is so populair, that when you point out a nice freeware tool like delinvfile, the respons is giving the creators some dollarsigns in their eyes. The same tool now sells for USD $ 26,95. So this freeware has become 'be aware'-ware. Unlocker v1.8.8 is still free (and works on Vista) and I also use Eraser for secure wiping.

Posted by: Egbert at December 31, 2009 1:24 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)

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!