Windows

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.

Previous post

Moving the root of a site in a subdirectory

Next post

How to delete Google Chrome favicon cache

Fulvio Sicurezza

Fulvio Sicurezza

11 Comments

  1. Danon Richards
    Wednesday December 14th, 2016 at 11:34 AM — Reply

    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!

  2. Frank Edwards
    Tuesday July 11th, 2017 at 04:21 AM — Reply

    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.

  3. Logan Govender
    Thursday March 8th, 2018 at 06:17 AM — Reply

    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.

  4. Mutaro
    Saturday March 10th, 2018 at 09:11 AM — Reply

    Thank you…

  5. Abhik
    Wednesday June 6th, 2018 at 03:31 PM — Reply

    This works like a dream!

  6. Joe
    Thursday September 6th, 2018 at 10:42 AM — Reply

    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!

  7. Mike Soucie
    Wednesday October 10th, 2018 at 03:57 PM — Reply

    Great workaround! Had a user with an infected file named con.exe. Anti-virus couldn’t remove it because of the filename.

  8. Radion
    Friday November 22nd, 2019 at 04:46 AM — Reply

    This worked for me where con.jpg was the file.

  9. Jane Austen
    Tuesday April 7th, 2020 at 06:45 PM — Reply

    thanks

  10. Paul Chancey
    Thursday July 2nd, 2020 at 04:14 PM — Reply

    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.

    • Darren Rose
      Tuesday July 14th, 2020 at 10:13 PM — Reply

      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

Leave a reply

Your email address will not be published. Required fields are marked *