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:
- In Explorer, Shift-right-click on the item to be deleted and select "Copy as path."
- In a command prompt, type DEL and then paste the name of the path you copied (right-click and select Paste).
- 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:\.
- 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
Related Q&A from Serdar Yegulalp
This week, our expert answers a question on how to connect a phone or tablet to a USB drive with a micro-USB connector. Continue Reading
Corrupt Windows user credentials can cause problems at login, but that's not the only thing that can interfere with a Windows user profile. Continue Reading
This week, our expert answers a question on mounting a disk volume as a read-only Windows disk partition, as in Linux. Just don't do it by accident. Continue Reading