When I try to save a file, if I use special characters in the name (such as a colon, question mark, or exclamation point) in Windows I get a message saying that the file name is invalid.
Why is that?
When I try to save a file, if I use special characters in the name (such as a colon, question mark, or exclamation point) in Windows I get a message saying that the file name is invalid.
Why is that?
There are several characters that have special meaning to Windows (and to DOS, where most of the characters originally came from)
from MSDN:
A filename cannot contain any of the following characters:
\ / : * ? " < > |
/
is a switch (and also a directory separator).
\
is a directory separator.
:
is a drive designator.
*
and ?
are wildcards used in searching.
"
is a way to allow spaces in parameters.
<
and >
are redirection that allow input and output of a program to come from, and go to, something other than screen/keyboard.
|
is a pipe that allows output from one program to be used as input to the next.
\
?
*
and "
are the only ones really necessary in the current syntax, as the other characters are only useful outside of quotation marks. The exception is : which is only useful as the second character, which could be outlawed while allowing it elsewhere. In other words, no file named A:A letter's story.txt
, but no problem with a file named Sarah: My favorite cat.txt
<>"
are reserved wildcard characters. Windows uses them to implement the complex semantics for DOS *?.
when translating to native NT, which has simple semantics for *?.
. The six wildcard characters are reserved because Windows implements wildcard matching in the file system itself, i.e. directly in the NtQueryDirectoryFile
system call, with no escaping mechanism. In Unix, wildcards are implemented at the application level, usually by a shell that supports escaping them.
:
is usually reserved in filenames, but not in file paths. It's used for device names and as the delimiter for file streams (e.g. "filename:streamname:streamtype"). Also, some file systems such as the VirtualBox shared-folder file system allow :
, |
, and ASCII control characters (1-31) in filenames, but they're reserved in all of Microsoft's file systems except for the named-pipe file system.