Access files with long paths (over 260)

The technique to convert MAXFILE encumbered DOS path names to native OS path names is well established and documented. Summarizing:

  • Prefix a path that uses a drive letter with \\?\, like \\?\C:\foo\bar\baz.txt
  • Prefix a path that uses a file share with '\\?\UNC\, like \\?\UNC\server\share\baz.txt.

Works well with FileSystemObject too, at least when I tested your code on Windows 10. That might not necessarily be the case in older Windows versions or with the network redirector on your server. Tested by using the FAR file manager to create subdirectories with long names and verified with:

Dim path = "\\?\C:\temp\LongNameTest"
ProcessFolder path

Produced:

\\?\c:\temp\LongNameTest\VeryLongFolderName0123456789012345678901234567890123456789012345678901234567890123456789\VeryLongFolderName0123456789012345678901234567890123456789012345678901234567890123456789\VeryLongFolderName0123456789012345678901234567890123456789012345678901234567890123456789\VeryLongFolderName0123456789012345678901234567890123456789012345678901234567890123456789\VeryLongFolderName0123456789012345678901234567890123456789012345678901234567890123456789\Chrysanthemum.jpg

Which is 488 characters long. Things to keep in mind:

  • Native path names must be full paths, they cannot be relative paths. In other words, they must always start with a drive letter or share name and start from the root of the drive/share.
  • You get the native path name back, don’t forget to strip the prefix off again if you display it.
  • Not tested but should fail, there is still a limitation on the the length of the filename itself (without the directory names), can’t be longer than 259 chars. Shouldn’t be a problem at all since the user can’t create them either.

Leave a Comment