Did you ever run into a Windows error message saying that the name of one of your files was too long and you wondered what caused this to happen? (Example below.) Here is an explanation of the limits on the length of a Windows file name.
Depending on the structure of the file system, there are various restrictions on how long a file name can be. It is important to remember that the length of a file name referred to here means all the information that the computer system needs to identify the file. That includes the drive and all the folders and subfolders involved. It may also involve certain kinds of other information about the structure of the file.
There are a variety of disk file systems, each with its own way of structuring the way a file is stored on a disk. Smaller USB devices may have an older system known as FAT32 and optical disks will have yet other file systems such as UDF or ISO9660. Most hard drives with Windows installed use the NTFS file system and that is the subject of this article.
There is some confusion in the numbers you see quoted in the computer literature for the maximum length of an NTFS file name because certain subtleties are often overlooked. To begin with, there is an absolute limit of 260 characters imposed by the Windows API. However, the practical limit is less than 260 characters. For example, all names have to have a null terminator at the end. Normally only the computer sees this end marker but it counts as a character so there are really only 259 characters available. Another three characters are used by the drive or volume designation (e.g., C:\). Thus, the limit for naming the containing folder and subfolders plus the name of the file itself is reduced to 256 characters.
However, there is a subtlety imposed by the way that Windows encodes characters. No individual object (file or folder) can have a name longer than 255 characters. This includes spaces and back slashes used as separators. This limit of 255 characters for an individual file name is often quoted but it applies only to file names in the root directory with no additional containing folders.
There is still another limit on the length of a file name that is often overlooked. There is usually a default option to provide an alternate name for a file using the old 8.3 naming system. When you create a new folder, Windows will reserve 12 characters for the alternate file name, leaving 244 characters for all containing folders. The creation of 8.3 names can be disabled but this can cause problems with very old 16-bit programs.
There is also a mechanism that makes much longer file names possible. For example, networked systems require more flexibility for file names. The Windows API provides special naming conventions to allow very long Unicode names in blocks of 255 characters. These long names are prefixed by "\\?\" (without the quotes). If you encounter a problem with a file name that is too long, try this prefix on the file name and path.
Following all the limitations can be confusing and I have summarized them in a table in this article that I wrote some time ago. This table makes the various limitations clear. Most instances of errors from overly long file names are caused by deeply-nested sub-folders. Knowing how many characters you are allowed will let you be careful in setting up the names and structure of your folders and avoid making names too long.
More information – http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx
Get your own favorite tip published! Know a neat tech tip or trick? Then why not have it published here and receive full credit? Click here to tell us your tip.
This tips section is maintained by Vic Laurie. Vic runs several websites with Windows how-to's, guides, and tutorials, including a site for learning about Windows and the Internet and another with Windows 7 tips.
Please rate this article: