[英]C++: GetTempPath() without tilde (~)
I need to get temp path.我需要获得临时路径。 So I tried GetTempPath() and std::getenv("TEMP").所以我尝试了 GetTempPath() 和 std::getenv("TEMP")。 The problem is that the result contains ~ symbol, for example C:\Users\OLEKSI~1.ALE\AppData\Local\Temp.问题在于结果包含 ~ 符号,例如 C:\Users\OLEKSI~1.ALE\AppData\Local\Temp。 Is it possible to get full temp path like C:\Users\Oleksii\AppData\Local\Temp?是否有可能获得完整的临时路径,如 C:\Users\Oleksii\AppData\Local\Temp?
GetLongPathName
function:获取长路径GetLongPathName
:
Converts the specified path to its long form.将指定路径转换为其长格式。
DWORD GetLongPathNameW(
[in] LPCWSTR lpszShortPath,
[out] LPWSTR lpszLongPath,
[in] DWORD cchBuffer
);
DWORD GetLongPathNameA(
[in] LPCSTR lpszShortPath,
[out] LPSTR lpszLongPath,
[in] DWORD cchBuffer
);
Set lpszShortPath
= short path with ~
symbols.使用~
符号设置lpszShortPath
= 短路径。 Read result from lpszLongPath
.从lpszLongPath
读取结果。
According to the Microsoft documentation :根据微软文档:
The GetTempPath function checks for the existence of environment variables in the following order and uses the first path found: GetTempPath function 按以下顺序检查环境变量是否存在,并使用找到的第一个路径:
- The path specified by the TMP environment variable. TMP 环境变量指定的路径。
- The path specified by the TEMP environment variable. TEMP 环境变量指定的路径。
- The path specified by the USERPROFILE environment variable. USERPROFILE 环境变量指定的路径。
- The Windows directory. Windows 目录。
Have you checked what these are set to?您是否检查过这些设置的内容? In Windows 10 you can press Windows+Break to open System Settings, then click Advanced system settings on the right, then click Environment Variables.在Windows 10可以按Windows+Break打开系统设置,然后点击右边的高级系统设置,再点击环境变量。 If TMP, TEMP or USERPROFILE are in there, check that they are set correctly and don't have the unwanted ~
in them.如果 TMP、TEMP 或 USERPROFILE 在那里,请检查它们是否设置正确并且其中没有不需要的~
。 If they're not, try adding them.如果不是,请尝试添加它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.