Wednesday, January 22, 2020

Solution to delete file name more longer than 255 characters in Windows

In Windows, when try to delete the file name more longer than 255 characters,
Diagnosing

  • Context menu will not appear.
  • Unable to rename in cmd
  • Unable to delete in cmd
  • Unable to delete using powershell programming
  • Unable to delete even in Java programming or any programming


Recommended solution

Use the subst command to assign a drive letter to a specific folder

You can substitute a specific folder path with a drive letter using the Windows Command Prompt and the subst command. The command follows the format:
subst <driveletter> <folder path>
For example, if you wanted to replace the folder path C:\Example\File\Path with the drive letter Y, you would enter:
subst Y: C:\Example\File\Path
Now the Y:drive is "mapped" directly to the folder. Since you have substituted most of the long file path with Y:, it no longer violates the character limit. You can now move the files out of this folder to a folder with a shorter file path.
After you move the files, you can delete the virtual drive by running the subst command with the /d parameter. To delete the Y: drive created in the example above, enter:
subst Y: /d

No comments: