Handle files with very long names in Windows

Handle files with very long names in Windows

Yesterday I stumbled upon a problem that is quite unusual: a user has been able to download a file with a very long name, and since Windows can only handle path of 259 characters for files it was impossible to delete or rename the file.

I tried in cmd to use the legacy DOS 8+3 name (FILENA~1.TXT) but still it was struggling recognizing the path.

So searching I found this solution that worked:

  1. Shift-right-click the file name in Explorer and select Copy as path.
  2. Open a Cmd window (-R cmd).
  3. Enter del \\?\ and then right-click to paste in the copied path. The result should look something like this:
    del \\?\"C:\Users\SomeUser\Downloads\VERYLO~1.TXT"
  4. Press Enter to delete the file.

 Note: In Windows 11, Copy as path is also available with just a right-click (i.e. shift not needed).

Source: https://answers.microsoft.com/en-us/windows/forum/all/cannot-delete-file-with-long-name/94bfa9ed-15fb-4816-8597-a6ae9cc656b7#:~:text=This%20issue%20appears,shift%20not%20needed