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