Search code examples
c++appdata

C++ : How to get actual folder path when the path has special folder names


I am trying to find a way to convert a path like this: "%APPDATA%\xyz\Logs\Archive" to this: "C:\Users\abcUser\AppData\Roaming\xyz\Logs\Archive".

I am on Windows platform. I use Unicode character set. I can use C++17 if required. I can use boost libraries if required.

In my search so far, I came across the SHGetKnownFolderPath() function. And there are StackOverflow references that explain how to resolve %APPDATA% to its actual path:

How do I get the application data path in Windows using C++?

C++ CreateDirectory() not working with APPDATA


Solution

  • The Win32 API that expands environment variable references of the form %variable% in strings is ExpandEnvironnmentStrings.