Filename
Mirror of English Wikipedia, the free encyclopedia
A filename is a special kind of string used to uniquely identify a file stored on a computer. Different operating systems impose different restrictions regarding length and allowed characters on filenames. The address (unique resource identifier - URI) of a file includes at least 4 different parts:
- computer id (IP address, domain name or LAN computer name eg: wikipedia.org, 207.142.131.206 or \\MYCOMPUTER )
- device(drive, root mountpoint, disc, volume, eg: C:, /)
- path (position in directory tree : everything between the first and last path separator)
- filename
In order to refer to a file on a remote computer (aka: host, server) its network id must be provided. If an URI does not contain a path part, the file is assumed to be in the current working directory.
Many systems, including DOS and UNIX, allow a filename extension that consists of one or more characters following the last period thus dividing the filename into two parts
- the basename (aka: proper filename, primary filename)
- and the extension (usually indicating the file type associated with a certain file format or mime type)
Within a single directory, filenames must be unique. However, two files in different directories may have the same name. Some operating systems, such as UNIX and the Macintosh operating system, allow a file to have more than one name, called an alias or hard link (see also: inode).
Note: These are different from windows shortcuts, symbolic links, soft links or hyperlinks.
Reserved characters and words
On all operating systems a filename might be prohibited from containing some or all of the following characters:
| Character | Name | Reason |
|---|---|---|
| any control character (0-31) | ||
| / | slash | used as a path separator in Unix-like systems |
| \ | backslash | used as a path separator in MS-DOS and Windows |
| ? | question mark | used as a wildcard in Windows and AmigaOS |
| * | asterisk | used as a wildcard in MS-DOS and Windows |
| : | colon | used to determine the mount point / drive on Windows; used to determine the virtual device or physical device such as a drive on AmigaOS; used as a pathname separator in classic Mac OS |
| | | vertical bar | designates software pipelining |
| " | quotation mark | used to mark beginning and end of filenames containing spaces |
| < | less than | used to redirect input |
| > | greater than | used to redirect output |
| . | period | allowed but the last occurrence will be interpreted to be the extension separator |
In Windows the space and the period are not allowed as the final character of a filename.
In addition, some words might also be reserved and can not be used as filenames. For example, DOS Device file:
CON, PRN, AUX, CLOCK$, NUL COM0, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9 LPT0, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9.
You must avoid using those reserved names as a filename suffix or file name body, eg: aux.c, file.aux or NUL.txt
The comparison of the filename in different operating systems
Although possible on most newer operating systems, for maximum portability it is not recommended to use non-ASCII characters or spaces when naming files. Also some file systems, such as most file systems on Unix and Unix-like systems, are case sensitive, meaning that, for example, a file named myFile cannot be referred to as myfile, and that files with both of those names can exist in the same directory, while other file systems, such as file systems on Windows and the HFS and HFS+ file systems on Mac OS, are case-insensitive, meaning that, for example, a filenamed myFile can be referred to as myfile (or MYFILE or MyFile), and only one file with any of those names can exist in a directory.
The maximum length of a filename including the extension on different file system/operating system combinations is:
| System | CaseSensitive | Allowed Charset | ReservedChars | Reserved Words | MaxLength | Comments |
|---|---|---|---|---|---|---|
| MS-DOS FAT | case-insensitive case-destruction | A-Z,0-9,-,_ | all except allowed | 12 | ||
| Commodore 64 | case-sensitive case-preservation | any | " | 16 | Flat filesystem with no subdirs. Space and shift-space are different chars. | |
| Win95 VFAT | case-insensitive | Any | \?*<":>+[] control characters | 255 | ||
| WinXP NTFS | optional | Any | \?*<":> control characters | aux, con, prn | 2048 | maximum length of entire url in IE |
| WinXP HPFS | case-insensitive case-preservation | Any | \?*<":> | 254 | ||
| Mac OS 9 (Classic) [[HFS+]] | case-insensitive case-preservation | Any | : | 255, though Finder limited to 31 | ||
| Mac OS X [[HFS+]] | case-insensitive case-preservation | Any | / at the Unix layer, : on disk and at the Carbon layer | 255 | ||
| most UNIX file systems | case-sensitive case-preservation | any | / | 255 | a leading . means ls and file managers will not by default show the file | |
| AmigaOS | case-insensitive case-preservation | any | :/" | 107 | dos.library | |
| Amiga OFS | case-insensitive case-preservation | any | :/" | 30 | Original File System 1985 | |
| Amiga FFS | case-insensitive case-preservation | any | :/" | 30 | Fast File System 1988 | |
| Amiga PFS | case-insensitive case-preservation | any | :/" | 255 | Professional File System 1998 | |
| Amiga SFS | case-insensitive case-preservation | any | :/" | 32000 | Smart File System 1998 |
Also: consider that ISO 9660 defines a maximum directory depth / level of 8, assuming a maximum length of 255, this leads to an overall maximum url length of 2040.
External links
- Naming a file (from MSDN) – filename restrictions on Windows

