Helping people with computers... one answer at a time.

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 « »

Share this article with your friends:

Share this article on Facebook Tweet this article Email a link to this article
Leo Leo A. Notenboom has been playing with computers since he was required to take a programming class in 1976. An 18 year career as a programmer at Microsoft soon followed. After "retiring" in 2001, Leo started Ask Leo! in 2003 as a place for answers to common computer and technical questions. More about Leo.

Not what you needed?

Recent Comments
121 Comments
jangadbutta
January 12, 2011 8:23 AM

Instead of using obsolete solution from www.longpathtool.com, you'd better visit the website of original manufacturer - www.pathtoolong.com - to download the latest version of Path Too Long.

Joe
February 10, 2011 9:59 AM

Being a Realtor, I'm used to typing abbreviations for things like St., Dr., Rd., etc. Well, after two years of trying to delete a file I noticed the "." at the end. This was the reason it would not delete as windows was looking for something like "com or exe" after the "." and never found it. Went into DOS, renamed the file, and it deleted just fine after that. Be careful of the evil "."!

Robin
February 17, 2011 2:21 PM

I have cracked this challenge for, say, "MyFile.doc ", by using
C:\ReName MyF*.* MyF*.doc

But BEWARE !

I had a file rid of which I COULD not get. It was at the end of a long path, with no other files, but I just COULD not delete it.

One day I set to, and eventually succeeded.

Alas.

For it was cross-linked, and I lost my entire MyPictures folder, and CHKDSK converted the contents into SEVENTY THOUSAND separate files !

I still have that hard disk untouched since then - does anyone know how I can retrieve any of the files ????

sean
December 20, 2012 1:52 AM

Thanks, Leo....
I had a problem with a file which i couldn't delete. A file that makes my processor to work slow. By following your instruction, the file has been deleted and my problem has been resolved...
thanks again dude!...

Randy Baker
March 24, 2013 9:34 PM

omg thank you so much!!!!!! i had a little 42k file and ive tried everthing! i downloaded DelinvFile from http://www.purgeie.com/delinv/dldelinv.htm and it worked .

Comments on this entry are closed.

If you have a question, start by using the search box up at the top of the page - there's a very good chance that your question has already been answered on Ask Leo!.

If you don't find your answer, head out to http://askleo.com/ask to ask your question.