Windows: how to fix “Invalid file handle” error
One reason for the “Invalid file handle” error in Windows when deleting a file is that a reserved name is used for its name.
Infact, as stated in this Microsoft article, during files/folders creation in Windows filesystem you should not use the following reserved names:
CON, PRN, AUX, NUL
COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9
LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, LPT9
Also avoid these names followed immediately by an extension; for example, NUL.txt is not recommended.
If for any reason you find yourself having to handle a file of this type, maybe copied from other file systems (eg. from a Linux PC with ext3/4 partition or from the internal memory of your smartphone), know that there are a couple of ways to delete these elements.
One solution is to delete file/folder from command prompt prefixing its full path with either \\.\ or \\?\.
For example, if you want to delete the C:\Temp\con\ folder, simply issue the following command at the prompt:
rd \\.\c:\Temp\con /S /Q
To delete instead the file C:\Temp\con.txt, the command to run will be:
del \\.\c:\Temp\con.txt
In other cases, where the reason for the “Handle Invalid file” is not attributable to its name, you can use the following command (assume that the file name is c:\Temp\test.txt):
fsutil reparsepoint delete c:\Temp\prova.txt del c:\Temp\prova.txt
A reparse point is an object in a file system with attributes that activate extended functionality. After you delete the reparse point with the first of the two commands above, you can delete the file with the standard procedure.
Finally, if both of these methods fail, probably your storage media is physically damaged, in which case the only options you have left are a deep scandisk or hardware replace.
11 Comments
Thank you so much. I was having a problem deleting CON.cif in the Cygwin installation. Cygwin’s website didn’t even reference this issue. Your article really helped resolve the problem fast!
Thank you very much. Finally I could delete CON.WAV, a file that I downloaded together with a bunch of other wav files. This article was very helpful for resolving my problem. Thanks again.
I have been Tearing my Hair out with the CON file, I have learnt something from your Article. Thanks a Lot. You have just made my Day.
You are a Star. Many Thanks. Have A Great Day.
Thank you…
This works like a dream!
Ciao, grazie per la guida! Sto cercando di eliminare il mio fastidiosissimo “Con.m4a”, ma non appena do il comando il prompt risponde così: “Impossibile trovare il percorso specificato”. Come posso risolvere? Grazie!
Great workaround! Had a user with an infected file named con.exe. Anti-virus couldn’t remove it because of the filename.
This worked for me where con.jpg was the file.
thanks
deleting is one solution, what is another? I need to keep the file. Its an archived communication that needs to be kept for legal reasons. It does not use any reserved windows words.
\\serverName\WEBCLAIMSINQUIRIES\0\1\1038.bin
I need to migrate it to another server and I cannot copy it or open it. Copy attempt gets the invalid file handle error, oen error simply says error.
try renaming it instead of deleting it?
also do it directly on server so you are accessing via a drive letter NOT a UNC path