Learning About Computers and the Internet
Tips Blog WinXP Internet Computing Downloads Vista/7 Home

Naming Windows Files - Restrictions and Limitations
There is more to a Windows file name than might be thought. The details of how the path, length and character considerations are involved are discussed.

You may think that nothing could be simpler than giving a name to a file. Actually, there are some rules; you can't name a Windows file just any old thing. Before discussing these rules, however, I need to make clear what some terms mean. The Web is full of somewhat conflicting information partly because of differing usage.

Clarifying the Terms "Path" and "File Name"

The term "path' is inconsistently used in computing literature. "Path" can mean the address or location of a file, i.e., the drive, folder, and subfolders where the file is stored, but it is also used by Microsoft and others to mean the file name together with the location. To add to the confusion, some use "path" to mean the file name and its containing folder(s) but do not include the drive or volume. In this discussion it is convenient to use "path" to mean the location including the drive. Also, what PC users sometimes mean by the term "file name" does not include the extension but in this discussion the extension is always an integral part of the file name. Here is an example of a file name (red) together with its path (blue).

D:\somefolder\somesubfolder\somefile.extension

Reserved Characters and Names

Most common characters can be used in naming files. However, the following characters are reserved and cannot be used in a file name: < > : " / \ | ? * Also, neither a space nor a period can be used at the end of a name. Further, files cannot have the following reserved device names: CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9. Note that the case does not matter in Windows.

Limits on the Length of File Names and Paths

There are also restrictions on the length of a file name and the length of the path. Conflicting numbers are to be found on the Internet because certain subtleties are often overlooked. I will try to make the various length restrictions clear.

We begin with the absolute limit imposed by Windows. The operating system API puts a limit (called MAX_PATH) of 260 characters for the complete name with the path included. This number is often quoted. However, actual limits are smaller because of various other restrictions. 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. (Forgetting to count the null terminator is a common mistake.) Another three characters are used by the drive or volume designation (e.g., C:\). Thus, the limit for naming all the folders and subfolders plus the file is reduced to 256 characters. However, no individual 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 per object is imposed by the way that Windows encodes characters but other considerations usually impose lower limits.

For one, there is a restriction that reduces the limit on the number of characters used for the path because it is the standard practice in Windows 32-bit systems to create an alternate short name in the old 8.3 format for all files. This means that at least 12 characters must be set aside for the file name. This leaves a maximum 244 characters for naming all folders and subfolders. This last limitation is often overlooked.

Although it is commonly stated that a file name can have up to 255 characters, this will generally be possible only if the file is in the root directory. As a practical matter, most file names will be limited to a smaller number because the number of characters needed for the names of any containing folders and their back-slash separators must be taken into account.

All of this may be hard to follow and Table I gives a summary that should help keep track of all the different length limitations.

Table I. Various limits for number of characters in file and path names
Item(s) Maximum number of characters Comments
All components together including null terminator
D:\somefolder\somesubfolder\somefile.extension{nul}
260 Limit imposed by Windows OS.
All components without null terminator. (Disk or volume plus folders plus file)
D:\somefolder\somesubfolder\somefile.extension
259 Actual limit since null terminator always uses up one character.
All folders plus file
somefolder\somesubfolder\somefile.extension
256 Number left after allowing three characters for disk or volume name.
File
somefile.extension
255 Limit imposed for any one object . Practical limit likely to be less unless file is in the root directory.
All folders
somefolder\somesubfolder\
244 Limit for folders imposed by the need to reserve characters for alternate 8.3 short names for files.

It is outside the scope of normal home use but, for completeness, I will mention that there are special naming conventions to allow very long Unicode names in blocks of 255 characters. These long names are prefixed by "\\?\" (without the quotes).

Practical considerations

One thing that may trip up a home user is a file that is located in a deeply-nested set of folders and subfolders. The file may not itself have a very long name but together with the whole path the string may stretch out to exceed the limits. Another situation where file names plus path can get very long is Internet Explorer favorites. These are actually files with the hidden extension URL. Internet Explorer favorites are usually in a folder \ Documents and Settings\{account name}\Favorites\ so the path already has quite a bit of length at the start. If you use folders and subfolders to organize your favorites, that also adds to the path length. Then the file name itself may be long if a Web master has packed a lot of key words in the name in order to affect search engine ranking. Sometimes the need at large sites for complex names just to keep track of things may give rise to a long name. Server generated pages can also contain a lot of characters.

Non-Windows length restrictions

Much more stringent length limits can arise when placing files on CDs or DVDs. These media use file systems that are different from Windows. There are a variety of systems but the two most common are called Joliet and UDF. Joliet is an extension of the earlier ISO 9660 File System. It is often used for writing to CDs. The maximum length that is allowed for a file name is 64 characters. The UDF system is often used for rewritable media and has a file name limitation of 128 characters. The specifications for CD and DVD burning software vary widely so the limits given are just indications. Newer software may be able to handle really long names (up to the Windows limit). Consult your CD/DVD burning software for specific details.

Some software may also have length restrictions.For example, it has been reported that Quicktime on Windows will not play a file with more than 63 characters in its name.

 


 << Home page ©2002-2014 Victor Laurie    Home page >>