Stopping too long filenames in Windows Server 2003

We're finding a problem with long filenames, usually on "My Documents" or on shared drives.

Basically, it seems that a document could be written that has a very long filename, and saved say in "My Documents". Which is fine on that computer, the document is "My Documents\verlylongfilename".

The problem arises when you got to the server the files are stored on, and the path changes to "e:\All Users\Staff Folders\JSmith\verylongfilename", which pushes the character count over what explorer can do anything with.

The only way I've found to "remove" or rename these files is to map through to the folder, but that's completely pointless if you want to move a group of folders.

Is this just a restriction we have to live with and fix as we find, or is there another way to access these files, or even to stop the original users from saving filenames over say 30 characters? A GPO setting maybe?


Solution 1:

The NTFS file system supports paths up to about 32767 Unicode characters with each path component (directory or filename) up to 255 characters long. But Windows Explorer and most other Win32 applications only support 255 characters in the path.

You could use robocopy, a free tool from Microsoft that fully supports long path names (longer than 256 characters). Here is documented how to use robocopy listing all switches and options.


Here's an excerpt from article on MSDN that explains why many programs limit paths to 255 characters:

In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX_PATH, which is defined as 260 characters. A local path is structured in the following order: drive letter, colon, backslash, components separated by backslashes, and a terminating null character. For example, the maximum path on drive D is

    D:\some 256 character path string<NUL>

where "" represents the invisible terminating null character for the current system codepage. (The characters < > are used here for visual clarity and cannot be part of a valid path string.)

Solution 2:

See http://www.ratsauce.co.uk/notablog/LongFileNames.asp

it's one of the sillier design decisions in the Windows NT family. As far as I know there is no way to prevent users creating the long file names.

JR

Solution 3:

I've had a similar problem while automating some parameterised purging on group and home drives.

I wrote a custom C# application to do it but to handle the long file names it was necessary to use the Unicode version of the Win32 api and not the usual Ascii version which has the limitations mentioned above. That also means prefixing the path string with \?\ if it's mapped or \?\UNC\ if it's through UNC.

I can give you some code samples or further info if you want.