views:

121

answers:

3

I need to get a %TEMP% environmental variable value string in Windows platform.

If I try to use any methods(C / C++) (getenv (), …) to get this environmental variable, it returns with “~” in that string.

For Example: C:\DOCUME~1\pkp\LOCALS~1\Temp.

But I need to get full string for some reasons, as below:

C:\Documents and Settings\pkp\Local Settings\Temp

If anyone knows any methodology to obtain this, please let me know.

+2  A: 

DOCUME~1 is not an environment variable. It is a legacy naming convention from DOS still supported by windows for backward compatibility. Hence there is nothing to 'expand' in the environment variable sense.

Alex
+3  A: 

Call GetLongPathName() on the short name.

unwind
Could you please suggest something in pure C++ i.e. without using the standard WINDOWS api.
anand
What a bizarre request!
Alex
But why do you find it bizarre. Is there any equivalent STL function for wordexp() http://www.opengroup.org/onlinepubs/009695399/functions/wordexp.html
anand
@anand: This is a Windows "feature", of course you're going to need to ask Windows for help in resolving it. There's no concept of Windows' 8.1 filenames in STL.
unwind
Thanks for the explanation. I dont have much idea OS other than windows. thanks again for the help!
anand
+1  A: 

You can use GetTempPath it obliges you to include "windows.h" but I assume you how to do that anyway since you're writing a windows app.

Serge
Could you please suggest something in pure C++ i.e. without using the standard WINDOWS api
anand
@anand - i'm not sure it's possible, except the way you did it with getenv
Serge