Platform SDK: Win32 API |
When an application creates a file or directory that has a long file name, the system automatically generates a corresponding short file name (alias) for that file or directory, using the standard 8.3 format. Aliases ensure that existing applications that do not handle long file names can, nevertheless, access those files and directories.
If the long file name follows the standard 8.3 format, the alias has the same name except that all lowercase letters are converted to uppercase. For example, if the long file name is Examples.Txt, the corresponding alias will be EXAMPLES.TXT.
If the long file name does not follow the standard 8.3 format, the system automatically generates an alias, using the following scheme to ensure that the alias has a unique name. The system tries to create a name by using the first 6 characters of the long file name followed by a numeric tail. A numeric tail consists of the tilde (~) character followed by a number. The system starts with the number 1 in the numeric tail. If that file name already exists, it uses the number 2. It continues in this fashion until a unique name is found. If the long file name has a file name extension, the system will use the first three characters of the long file name's extension as the extension for the alias.
As the number of digits in the numeric tail grows, fewer characters in the long file name are used for the 8 characters in the alias. For example, the alias for Long File Name.File would be LONGFI~10.FIL if the names LONGFI~1.FIL through LONGFI~9.FIL already existed in the directory. Applications can override the default alias numbering scheme when creating a file by specifying the OPEN_FLAGS_ALIAS_HINT value and supplying a number to use in the call to Create or Open File (Interrupt 21h Function 716Ch).
A period is just another character in a long file name. Leading periods are allowed in a long file name, but trailing periods are stripped. A file can have multiple periods as part of its name. For example, MyFile.081293.Document is a valid file name, and its alias will be MYFILE~1.DOC. The first three characters after the last period in the file name are used as the file name extension for the alias, as long as the last period is not a leading period. A file name of .login is also valid, and its alias is LOGIN~1.
In a given directory, the long file name and its alias must uniquely identify a file. For example, if there is a file with the long file name Long File Name and the alias LONGFI~1, the system will not allow either Long File Name or LONGFI~1 to be used as another file's long file name.
If a file with a long file name is copied or edited, the alias for the resulting file may be different from the original alias. For example, if the destination directory contains an alias that conflicts with the original alias, the system generates another unique alias. If a long file name LongFile name is associated with the alias LONGFI~2 and is later copied to a different directory using the long file name, the alias in the destination directory might be LONGFI~1 (unless a file with that name already existed in the destination directory). The system always generates new aliases during these operations and always chooses aliases that do not conflict with existing file names. An application must never rely on an alias being the same for all copies and versions of a given file.
Applications can open, read, and write from a file using the alias without affecting the long file name. However, some operations on the alias, such as copy, move, backup, and restore, may result in the original long file name being destroyed. For example, older versions of utilities that do not support long file names can destroy the long file name while performing those operations.
The system attempts to preserve a long file name, even when the file associated with it is edited by an application that is not aware of long file names. Typically, these applications operate on a temporary copy of the file, and when the user elects to save the file, the application deletes the destination file or renames it to another name. The application then renames the temporary file to the destination name or creates a new file with new contents.
When an application makes a system call to delete or rename an alias, the system first gathers and saves a packet of information about the file and then performs the delete or rename operation. The information saved includes the long file name as well as the creation date and time, the last modification date and time, and the last access date of the original file. After the system performs the delete or rename operation, the system watches for a short period of time (the default is 15 seconds) to see if a call is made to create or rename a file with the same name. If the system detects a create or rename operation of a recently deleted alias, it applies the packet of information that it had saved to the new file, thus preserving the long file name.
Currently, Load and Execute Program (Interrupt 21h Function 4B00h) does not accept long file names. If an application starts other applications, it must retrieve the file name alias for the given executable file and pass that alias to Load and Execute Program.