Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

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.)

share|improve this answer
    
"most other Win32 applications only support 255 characters in the path" - Does that include the 64bit servers as well? –  Tubs Jun 9 '09 at 12:34
    
I tested this using Windows Explorer on Vista 64. I created a 100 characters long folder and a sub folder with 100 characters. Explorer broke the name of the third folder, which is a sign that paths are handled the same way like on 32bit machines. –  splattne Jun 9 '09 at 12:45

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

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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