Best Practice to Sync Long Paths to Filesystems with Path Length Limits

file-storagefile-systemspatterns-and-practicessynchronization

I wrote a sync tool to synchronize folders/files from Alfresco to Windows.
PROBLEM:

  • In Alfresco, /files/can/have/very/very/very/long/filepaths/like/this.txt
  • The Windows API prevents me from creating a path with more than 260 characters.

In addition to telling the user there is a problem, what is the best practice in such a case?

  1. Shorten the file's name?
  2. Skip the file?
  3. Create a sort of "folder's carriage return", a special folder from which the path can continue?
  4. Something else?

Files need to be 100% usable by other applications. If necessary directory names can be modified, I can keep a mapping.

Best Answer

The problem you mention doesn't exist, since the limit you specified in your question is wrong.

  • Until Vista, Explorer was limited to 248 characters.
  • .NET Framework File is limited to 260 characters (MAX_PATH).
  • The real maximum path for Windows itself is approx. 32,767 characters.

I have no idea where have you found the mention of 255 characters.

Now, if you're syncing files to an operating system which doesn't allow 32,767 characters-length paths (like very old versions of Windows), then:

  • Skip the file,
  • Inform the user that there is an issue with the length of the given files. Do it only at the end of the process, not file by file. There is nothing more annoying that being disturbed dozens of times during a process because there are dozens of files that cannot be synced.
  • Don't shorten the file name. You have a good chance to cause more trouble with collisions.