Canonical filesystem path formatting is invalid after conversion to const char *
I am trying to convert a relative path and convert it to absolute in order to go to SQLite using boost filesystem. This should work correctly for windows and linux
boost::filesystem::path path("../../data/dominion");
boost::filesystem::path file("dominion.db");
boost::filesystem::path canonical = boost::filesystem::canonical(dataPath / file);
canon returns
m_pathname=L"D:/Users\\me\\Documents\\tonkatsu\\data\\dominion\\dominion.db"
As you can see, the beginning of the "D: /" path is incorrect. I have also tried calling normalize () on it with no success
Is there a way to fix this?
source to share
Although not standard practice, slashes are also accepted on Windows, so boost doesn't force the conversion.
However, some libraries will not accept forward slashes. [1] is intended to address such situations by converting the path to the preferred system representation (ie using a backslash on Windows).boost::filesystem::path::make_preferred()
[1] This old link makes this behavior more obvious
As described below, while (most) Windows APIs accept forward slashes and even a mixture of forward and backslashes, some UIs even for applications included with Windows do not work.
source to share