Long filenames, NTFS and legal filename characters
Long file names - If a filename contains spaces you must surround it "with double quotes" Filenames that include quotes or brackets (') - these are legal filenames but they can cause problems.
Short file names - The order in which you create files will affect short
8.3 names
e.g.
echo abc > "a long file 1.txt"
echo abc > "a long file 3.txt"
echo abc > "a long file 2.txt"
DIR /x
:: will produce this:
ALONGF~1.TXT a long file 1.txt
ALONGF~3.TXT a long file 2.txt
ALONGF~2.TXT a long file 3.txt
If these files are now copied to another folder the 8.3 filenames will change,
this is most likely to happen when upgrading server storage or restoring data
from a backup.
Similarly for folders
md "a long folder 1"
md "a long folder 3"
md "a long folder 2"
DIR /x
:: will produce this:
ALONGF~1 a long folder 1
ALONGF~3 a long folder 2
ALONGF~2 a long folder 3
Again copying these to somewhere else will change the 8.3 names to:
ALONGF~1 a long folder 1
ALONGF~2 a long folder 2
ALONGF~3 a long folder 3
See the Wildcards page for more long/short filename issues.
To disable the use of 8.3 filenames
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem]
NtfsDisable8dot3NameCreation=0
Batch files .BAT or .CMD ?
Batch files can be saved with the extension .BAT or .CMD
The .BAT extension will run under Windows 95/MSDOS but the .CMD extension will only run under NT, XP or 2003.
It is therefore advisable to use .CMD if the script uses commands that wont run (or wont run correctly) under Win 95.
NTFS file system
Legal characters in NTFS include the following:
[ ] . ; = ( )
The period (.) cannot be the first or only character in the filename
Illegal Characters: The following characters are not permitted in Windows file or directory names:
/ \ : * ? " < > |
A long file name (LFN) can be up to 255 characters long.
NTFS supports paths up to 32768 characters in length, but only when using the Unicode APIs.
When using very long path names, prefix the path with the characters \\?\ and use the Unicode versions of the C Runtime functions.
8.3 format filenames
These
can have between 1 and 8 characters in the file name. Short file names have the 8.3 format and are compatible with MS-DOS and other legacy operating systems.
The name must start with a letter or a number and can contain any characters except the following:
/ \ : * ? " [ ] | = , . ; (space)
An 8.3 file name typically has a file name extension between one and three characters long with the same character restrictions. A period separates the file name from the file name extension.
It should be noted that some characters are invalid in 8.3 format filenames but are valid in NTFS filenames and are also valid Delimiters Typically the Windows GUI will silently rename such files where neccecary.
You can use long file names in both NTFS and FAT volumes.
Special file names reserved by the system (cannot be used for files or folders)
CON, AUX, COM1, COM2, COM3, COM4, LPT1, LPT2, LPT3, PRN, NUL
Related:
Escape Characters, Delimiters and Quotes