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

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

Your Name:
Your Email:


Why Subscribe?

Recent Comments
104 Comments

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 7:06 PM

Error Deleting File or Folder

We all have had the experience of seeing the Windows Error Deleting File or Folder – Cannot delete : It is being used by another person or program.

If you are unable to delete a file or folder when the only program running is Windows Explorer, the Windows application Explorer is usually* the program at fault. Explorer since day one has had a problem with releasing file locks but, you can use the following manual procedure to delete any file or folder.

You must be sure the file or folder you want to delete is not needed by either the operating system or an application. If you are unsure you can use the program Process Explorer to determine which program process has a lock on the file or folder. You can download the program for free at the www.sysinternals.com which, re-directs you to the Microsoft TechNet website http://technet.microsoft.com/en-us/sysinternals/default.aspx. After installing Process Explorer you can use the Find menu then select the File Handle or DLL option (ctrl-F) and type in the name of the file or folder name and learn the name of the program preventing the file or folder deletion. In any event, Process Explorer is a good addition to your toolkit.

So if you’re ready to get rid of that pesky file or folder print out the following instructions:

1) Close all applications and open Windows Explorer (if you were unable to print out the instructions leave the application with the instructions open and use the ALT-Tab to toggle between applications later when we stop Explorer)
2) If you don’t have the Address toolbar active in Explorer go to the View menu click Toolbars then click Address Bar
3) Locate the file you want to delete and click on it OR to delete a folder locate the folder containing the folder you want to delete and click on it
4) Right-click in the Address toolbar box and select Copy which copies the drive and pathname to the Clipboard
5) Close Windows Explorer
6) Press the Ctrl-Alt-Del keys simultaneously to open Windows Task Manager
7) Click on the Processes tab
8) Click on the Image Name column to sort the processes running alphabetically
9) Find the Explorer.exe process and click on it
10) Click the End Process button
11) Click the Yes button In the Task Manager Warning message box
12) Click on the Applications tab
13) Click on the New Task button
14) In the Open box type the letters “cmd” and click OK to open the command interpreter
15) Type the letters “cd “ (the letters cd followed by a space) and right-click then select Paste and press Enter (this will change the directory to the directory we copied from the Address toolbar)
16) Type the letters “dir” and press Enter (this displays all the files and folders in the directory)
17) Locate the file or folder name you want to delete (use the scroll bar if this is a directory with a lot of files)
18) Right-click anywhere inside the window and select Mark
19) Left-click on the first letter of the file or folder name to highlight the first letter
20) Hold the shift key down and left-click on the last letter of the file or folder name (the whole file or folder name should now be highlighted)
21) Press Enter (this will copy the highlighted file or folder name)
22) To delete a file type in the letters “del “ (the letters del followed by a space) or to remove a directory type in the letters “rd “ (the letters rd followed by a space)
23) Right-click and select Paste
24) Press Enter (this will delete the file or remove the folder)
25) Type in the letters “exit” and press Enter to exit the command interpreter
26) In the Windows Task Manager click on the New Task button
27) Type in the letters “explorer” and click the OK button
28) Close the Windows Task Manager

I noticed mention of software here that could remove these files automatically. Unfortunately they seem to require the system to reboot and in the case of Malewarebytes 'FileASSASSIN', it doesn’t work when Explorer is the process that is keeping you from deleting the file. I’m so used to doing the above procedure that I could delete the file in the time it takes Windows to shutdown let alone wait for Windows to start.

*The above procedure has worked for me 100% of the time for deleting files or folders when a registered process controls the file. The only time I was unable to use this procedure was when a “malware” program had control of the file I was trying to delete. At that time I had never heard of “malware” and I was in the process of manually detecting and removing what I thought to be a virus, trojan or worm which was attacking my system. I never use to use virus or worm prevention software because they are such resource hogs and they can cause many other problems. I’ve since found out the anti-virus software I renewed was worthless against “malware”, but not until I renewed the expired license, that came with the computer. After renewing the license I used the software to scan for viruses, worms and Trojans: the software found none. Meanwhile, it was getting just about impossible for me use Internet Explorer. After some painfully slow research I learned my computer was infected by a “malware” program, which led me to the free version of the program, Malwarebytes' Anti-Malware. With much trepidation, I downloaded the free version of the program and installed it. When I ran the program it found the registry entries and infected files and removed them. Ironically, the malicious programs that Malwarebytes found were Trojan.Vundo, Trojan.BHO, Trojan.Agent and Rootkit.Agent. So much for protection the virus protection I paid to renew!

In the process of writing this I ran the malware program to look at the history and checked for updates. When I let the program update the definitions, my virus protection software wouldn’t let one of the files download because it detected a Trojan named Generic.dx in the directory of the Malwarebytes program directory while the update program was attempting to copy files.

That’s just great, now I’ve got an Anti-virus vs. Malware software war brewing!

There’s a reason I kept this stuff off my system all these years.

I hope you find this procedure as useful.

Tom

Posted by: Tom at October 4, 2008 9:13 PM

In my previous post I forgot about file names and folder names with imbedded blanks that need to be enclosed in double-quotes. Replace steps 22 and 23 with the following:

22) To delete a file type in the characters del “ (the letters del followed by a space and a double quote) or to remove a directory type in the characters rd “ (the letters rd followed by a space and a double-quote)
23) Right-click and select Paste and then type the character “ (double-quote) the fully constructed commands look like - del “file name.ext” OR rd “folder name”

Sorry for the over-sight. I think I could use a good a QA person.

Tom

Posted by: Tom at October 4, 2008 10:47 PM

Removing a Windows file is easy, once you figure out what the file is and where it is located. I use this procedure all the time for my wife, who is unwilling to learn a different operating system.
1. Boot the system from a CD with a live Linux distribution such as Knoppix, Fedora or Ubuntu.
2. Mount the Windows filesystem in Linux, which has no problem reading and writing Windows filesystems.
3. Delete the file with the command "rm ".
Of course, it's not quite that simple, and you need to know that removing the file won't corrupt Windwos so that it won't run, but once you learn a little Linux, it's easier than all the crap you have to go through trying one program after another in Windows. Or you can avoid these problems entirely by using Linux, which these days comes with extensive driver support, easy installation, and an OS more stable and faster than Windows. Oh, and it's free for download, of course. Some very good distributions are Knoppix, Fedora 9, Ubuntu 8.04 and OpenSuse 11.0.

Posted by: Khentiamentiu at October 14, 2008 12:35 PM

oh God,, there are 100 comments for this Post. I do not think my comment would matter much,, haha,, But wow thanks for solving my problem..And I must say I discovered a new tool .. wow it works great,,

Posted by: Bikesh at December 16, 2008 9:23 AM

Read all the comments (on this and other websites) and can't find mention of this solution. Reboot in Safe mode - use Explorer to go to the file, select and delete. This has always worked for me!

Posted by: Geoff at February 4, 2009 9:00 PM

HHOOOORRAAAY!!

Unlocker WORKED!. After weeks and weeks of struggle - and I am not a newbie when it comes to Windoze crap. MOveOnBoot did NOT work, unlocker did! I'm sending him a donation!

Steve

Posted by: Steve Crye at February 26, 2009 9:09 PM

cant find it in my add and remove to delete it out please help me delete this from my sytem

Posted by: rachel searles at March 4, 2009 5:56 AM

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...

Please wait. Your comment is being processed ...


Question? Ask Leo!