| |
|
All computer systems have rules about naming files and directories (folders). The rules are not arbitrary but exist because some characters have special meanings to the computer system itself.
If you use these "illegal characters" (that's what they are called) in a file name they could cause the system to yield bizarre results - or even to crash - if the system attempts to perform certain processes on these erroneously named files.
[understatement] Windows has a few quirks [/understatement]. One of these quirks is that Windows frequently will allow you to save a file with "illegal" file name - a name that contains illegal chracters. Yet, when you try to re-open the file, or perform system processes, Windows balks or even brings the system to its knee's. (Can we say "Crash", or BSOD - Blue Screen Of Death.).
To avoid these problem don't use illegal characters in filenames. Illegal Windows file name characters are as follows:
? [ ] / \ = + < > : ; " , *
In addition, names of files destined for posting on a website should not contain spaces,
upper case letters,
%
or the Illegal characters listed above.
Basic Naming Conventions
The following fundamental rules enable applications to create and process valid names for files and directories, regardless of the file system:
- Use a period to separate the base file name from the extension in the name of a directory or file.
- Use a backslash (\) to separate the components of a path. The backslash divides the file name from the path to it, and one directory name from another directory name in a path.
- Use a backslash as required as part of volume names, for example, the "C:\" in "C:\path\file" or the "\\server\share" in "\\server\share\path\file" for Universal Naming Convention (UNC) names. You cannot use a backslash in the actual file or directory name components because it separates the names into components.
- Use almost any character in the current code page for a name, including Unicode characters and characters in the extended character set (128–255), except for the following:
- The following reserved characters are not allowed:
< > : " / \ | ? *
- Characters whose integer representations are in the range from zero through 31 are not allowed.
- Any other character that the target file system does not allow.
- Use a period as a directory component in a path to represent the current directory, for example ".\tmp.txt".
- Use two consecutive periods (..) as a directory component in a path to represent the parent of the current directory, for example "..\tmp.txt".
- Do not use the following reserved device names for the name of a file:
CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9
Also avoid these names followed immediately by an extension; for example, NUL.txt is not recommended.
- Do not assume case sensitivity. For example, consider the names OSCAR, Oscar, and oscar to be the same, even though some file systems (such as a POSIX-compliant file system) may consider them as different.
- Do not end a file or directory name with a trailing space or a period. Although the underlying file system may support such names, the operating system does not. However, it is acceptable to start a name with a period.
Maximum Path Length
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 "<NUL>" 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.) |
|