Skip to content

Maximum number of characters in a Windows path is 260 characters

February 28, 2012

A Java project compilation went berserk and I ended up with a directory structure of more than 260 characters. I stopped the mad process but it already created more than 50 successive duo of path “build/classes” …

Duo of build/classes directories in path created by Netbeans

Now I had to delete this structure. And, to my surprise, it was impossible. When you try to just press the “Delete” key with the root directory selected in the File Explorer, you get a Path Too Long exception. The reason is that the maximum length of a path according to the Windows API (MAX_PATH variable) is defined as 260 characters. I tried some other methods but all of them failed:

  • write a small Java program that tried to delete the whole path: Netbeans (Java) was able to create this mess, why shouldn’t another Java program be able to delete it? Impossible.
  • write a small C++ program that tried to delete the whole path: as long as you stick with the Windows API, it’s impossible (I read that it could be possible using the boost::filesystem library but didn’t try).
  • try some Portable Apps utilities for file management: impossible (even when the software was using another framework like Qt).

Finally, I just ran a Cygwin terminal, went to the ad hoc location and did a simple “rm -rf libtest“. And voilà. So, next time Windows forbids me from doing something, it might be a good idea to directly rely on a true terminal from a Unix-like environment. I didn’t try a liveCD (I didn’t have such CD to hand) but it might be also possible.

From → Projects

3 Comments
  1. EthanGreg permalink

    I had the similar problem and faced it a lot of times. I often solve this type of problems using “Long Path Tool”. It helped me in solving this error and all related errors. I hope you will also love it.

  2. Thanks for the tip, EthanGreg. Maybe you can share the overall technique used by your tool to solve the issue?

    • EthanGreg permalink

      OK. I’ll describe the overall technique, when I get some free time.

Comments are closed.

%d bloggers like this: