CString csFilePathName;
::ExpandEnvironmentStrings(_T("%ProgramData%"), csFilePathName.GetBuffer(MAX_PATH), MAX_PATH);
csFilePathName.ReleaseBuffer();
csFilePathName += _T("Test.txt");
if (PathFileExists(csFilePathName))
{
//Other operation
}
本文介绍了一个使用 C++ 在 Windows 环境下处理路径的方法。具体实现为:通过调用 ::ExpandEnvironmentStrings 函数将环境变量展开为实际路径,并附加文件名 Test.txt 到该路径中,最后检查文件是否存在。
CString csFilePathName;
::ExpandEnvironmentStrings(_T("%ProgramData%"), csFilePathName.GetBuffer(MAX_PATH), MAX_PATH);
csFilePathName.ReleaseBuffer();
csFilePathName += _T("Test.txt");
if (PathFileExists(csFilePathName))
{
//Other operation
}

被折叠的 条评论
为什么被折叠?