File Name Too Long (for just Windows Explorer)

Posted on

QUESTION :

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:Expandtfs2010Healthcare-Finance_ITMainMLR Rebates Web ServicesLoad_MLR_REBATE_IBOR_INFOLoad_MLR_REBATE_IBOR_INFOService ReferencesIborServiceReferenceLoad_MLR_REBATE_IBOR_INFO.IborServiceReference.locateProfileBySourceSystemIdResponse.datasource

enter image description here

ANSWER :

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:Usershi vs. C:UsersHI). 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.

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, “\?UNCservershare“, 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.

Leave a Reply

Your email address will not be published.