One of the things that's been bugging me recently though is how to use non ASCII file names in paths on Windows. The problem that I encountered was that boost would throw this exception:
boost::filesystem::create_directory: The filename, directory name, or volume label syntax is incorrect:
every time I try to e.g. create a directory with a non-ASCII name (e.g. something in cyrillic). After digging the net for a while I've found this in the Boost filesystem documentation
The default imbued locale provides aThis was what I was looking for. Setting which code page to use for the conversion is then done with:codecvtfacet that invokes WindowsMultiByteToWideCharorWideCharToMultiByteAPI's with a codepage ofCP_THREAD_ACPif WindowsAreFileApisANSI()is true, otherwise codepageCP_OEMCP.
#ifdef OS_WINDOWS
SetFileApisToOEM();
#endif
Also you have to use a wstring instead of a regular string to construct the boost::filesystem::path object. A very useful page that explains the internationalization aspects of char and wchar_t is this excellent answer.
0 comments:
Post a Comment