September 29th, 2006

Quotation marks around spaces aren't necessary in the PATH environment variable

The purpose of quotation marks is to allow a character that would normally be interpreted as a delimiter to be included as part of a file name. Most of the time, this delimiter is the space. The CreateProcess function uses a space to separate the program name from its arguments. Most programs separate their command line arguments with a space. But the PATH environment variable doesn’t use spaces to separate directories. It uses semicolons. This means that if you want to add a directory with spaces in its name to the path, you don’t need quotation marks since spaces mean nothing to the PATH environment variable. The quotation marks don’t hurt, mind you, but they don’t help either.

On the other hand, if the directory you want to add contains a semicolon in its name, then you do need the quotation marks, because it’s the semicolon that you need to protect.

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.