I have a directory containing a file that I want to delete. However, the name of the file is too long:

> Remove-Item -Recurse target
Remove-Item : The specified path, file name, or both are too long. The fully qualified
file name must be less than 260 characters, and the directory name must be less than
248 characters.

I cannot delete it with shift+delete in Windows Explorer either:


I cannot move the file either, since its name is too long. Is there any way I can delete the file? I use Windows 8.1. Bonus points if you can explain how such a file could end up on my drive in the first place, and why Explorer and PowerShell can't delete it.


1 Answer 1


You should be able to do that using a DeleteFile() and path using the long path notation like \\?\C:\path\to\your\file.class.

From the linked MSDN page:

In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see Naming a File.