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.

  • 1
    To clarify this answer, these special characters could interfere with parsing a command line (or path) if they were in a filename. There is no requirement to delimit the filename in any way (e.g. surround it with quotes or spaces), so encountering such a special char would cause incorrect parsing (i.e is the special char part of the filename or an operator?). – sawdust Dec 27 '13 at 20:41
  • 1
    It is, however, arguable that some of these restrictions are no longer necessary due to the handling of long filenames and quotations marks. \ ? * 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 – trlkly Jun 5 '14 at 23:41

I have come across people using "." as part of a file name (ie SKH.001.DWG). I think "." should also be added to this list of canbnot be used as part of a document name, or at least a warning of where it is appropriate or not.

  • 2
    Welcome to Super User. Can you expand your answer a little? For example, why should "," not be used and in what kinds of circumstances can it cause problems? Of course none of us can influence what Microsoft puts in its list. :-) – fixer1234 Aug 12 at 21:04

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.