How to delete a file or folder when the Windows path is too long

Our expert answers a question on how to delete a file or folder when its Windows file name is beyond the Windows path length limit.

How do I delete files or folders when Windows complains "the path is too long?"

Windows has a number of rules on the maximum lengths possible for file names, directory names and path names. The maximum length for a Windows path name is generally 260 characters, although Windows also maintains -- via a parallel set of file-access application programming interfaces (APIs) -- the ability to access paths that are 32,767 characters long. Note that the latter way of accessing file paths is always absolute; you can't have a relative path name longer than 260 characters.

Because Windows is designed to err on the side of backward compatibility, the system defaults to using the old way of using path names. Many older programs would simply break if forced to work with the new API. The new path-name system requires a different naming convention for a path to alert the system about whichever file API you want to work with. Explorer and the command line default to the old naming system, which is why attempting to work with a path name that's too long will throw an error.

If you end up with a Windows path that is apparently too deep to be deleted, you can force the use of the alternate file-designation methodology to get around the 260-character limit. Here's how to do it:

  1. In Explorer, Shift-right-click on the item to be deleted and select "Copy as path."
  2. In a command prompt, type DEL and then paste the name of the path you copied (right-click and select Paste).
  3. Press Home to go to the beginning of the line, and modify the drive letter for the Windows path so that it reads \\?\<driveletter>:\. For example, if the path begins with D:\, modify so it reads \\?\D:\.
  4. Windows should delete the file or folder successfully.

Do you have questions for our experts? Email [email protected].

Dig Deeper on User passwords and network permissions