How to get a full path to Temp and Application Data
-
In view of the system file
Temp
TotalWINDOWS\
andApplication Data
(sighs)%APPDATA%
)
-
%APPDATA%
e.g. functionSHGetFolderPath
orgetenv
from the standard library,%TEMP%
for the current user . -GetTempPath
or the samegetenv
♪ Here's to get file ♪%TEMP%
I have to use the function.ExpandEnvironmentStringsForUser
:#include <iostream>
#include <windows.h>
#include <Shlobj.h>
#include <Userenv.h>int main()
{
TCHAR szPath[MAX_PATH];
char* path;if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, szPath))) { std::cout << "%APPDATA% (SHGetFolderPath) = " << szPath << std::endl; } path = getenv("APPDATA"); if (path != NULL) { std::cout << "%APPDATA% (getenv) = " << path << std::endl; } if (GetTempPath(MAX_PATH, szPath)) { std::cout << "User's %TEMP% (GetTempPath) = " << szPath << std::endl; } path = getenv("TEMP"); if (path != NULL) { std::cout << "User's %TEMP% (getenv) = " << path << std::endl; } if (ExpandEnvironmentStringsForUser(NULL, "%TEMP%", szPath, MAX_PATH)) { std::cout << "System's %TEMP% = " << szPath << std::endl; } return 0;
}
For use
ExpandEnvironmentStringsForUser
We're gonna need to get attached.Userenv.dll
♪