7

When I was copying a directory structure to a new location where the target folder had a name slightly longer that the source, I encountered the following error indicating that the file name was too long.

The interesting part is that I then used Scooter Software's Beyond Compare app to compare the Source folder to the target folder to identify the files that failed to copy. I was suprised to find that BC was able to copy the files to the target folder so both folders matched 100%.

I think the file name in question was 258 characters long. Previously, based on error messages that I probably seen in Windows Explorer, I thought that Windows had a 255 character limit on file names, including path. Since I was able to copy the following 258 char file name using Beyond Compare, this appears not be be the case.

Is there a Windows file name length limit? Why is Windows Exploere's max length 255?

It looks to me like the "name too long" restriction was

C:\Expand\tfs2010\Healthcare-Finance_IT\Main\MLR Rebates Web Services\Load_MLR_REBATE_IBOR_INFO\Load_MLR_REBATE_IBOR_INFO\Service References\IborServiceReference\Load_MLR_REBATE_IBOR_INFO.IborServiceReference.locateProfileBySourceSystemIdResponse.datasource

enter image description here

1

2 Answers 2

4

The underlying filesystem of Windows, NTFS, is much more flexible than the legacy Win32 Subsystem (win32k.sys) gives it credit for. By accessing NTFS directly and bypassing the Windows Shell, a lot of interesting possibilities appear, such as having files in the same directory whose names differ only in case (like C:\Users\hi vs. C:\Users\HI). File path length limits are another one of these legacy limitations that harkens back to Windows 95 or earlier (perhaps even DOS). Beyond Compare appears to be bypassing the Windows Shell, which is a very wise thing to do indeed for a robust file copy program.

See here for Microsoft's official answer.

4
  • 2
    your link is ... the end-user version and does not provide the "whole" story: msdn.microsoft.com/en-us/library/windows/desktop/… .. in short, if OP would use unc-paths explorer would be able to access / copy the files as well, because then it would switch to the unicode-version of the file api which puts a 32k limit onto the filename.
    – akira
    Jan 28, 2014 at 22:12
  • @akira: Windows Explorer (at least before Win10) doesn't support the UNC path syntax, so it can't be used as a workaround unfortunately.
    – Malvineous
    Jan 27, 2017 at 7:14
  • @Malvineous it does. \\?\C:\Users for example works flawlessly, even in a Win7-WindowsExplorer.
    – akira
    Jan 29, 2017 at 11:12
  • @akira: It "works" but only because Explorer converts it back to the old-style notation. Try creating a folder path longer than 260 characters and you'll see that even putting \\?\ on the front won't let you access it in Explorer.
    – Malvineous
    Jan 29, 2017 at 12:42
0

The maximum path length in Windows is 32,767 characters.

To specify such a path use the \\?\UNC\ prefix, i.e. a UNC path.

For example, "\\?\UNC\server\share", where "server" is the name of the computer and "share" is the name of the shared folder.

These prefixes are not used as part of the path itself. They indicate that the path should be passed to the system with minimal modification, which means you cannot use forward slashes to represent path separators, nor a period to represent the current directory, nor double dots to represent the parent directory.

Because you cannot use the "\\?\" prefix with a relative path, relative paths are always limited to a total of MAX_PATH characters, i.e. are limited to 260 characters.

Not the answer you're looking for? Browse other questions tagged or ask your own question.