December 24th, 2004

Why does the system convert TEMP to a short file name?

When you set environment variables with the System control panel, the TEMP and TMP variables are silently converted to their short file name equivalents (if possible). Why is that?

For compatibility, of course.

It is very common for batch files to assume that the paths referred to by the %TEMP% and %TMP% environment variables do not contain any embedded spaces. (Other programs may also make this assumption, but batch files are the most common place where you run into this problem.)

I say “if possible” because you can disable short name generation, in which case there is no short name equivalent, and the path remains in its original long form.

If you are crazy enough to set this value and point your TEMP/TMP variables at a directory whose name contains spaces and doesn’t have a short name, then you get to see what sorts of things stop working properly. Don’t say I didn’t warn you.

Topics
Code

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.