How-To convert filesystem paths between WIN32 and POSIX
This library functionality helps when std::filesystem::path
is unavailable
or too heavy-weight. Often, one just needs to abstract out file system path
differences between POSIX-like systems and Windows.
We provide two functions for converting back and forth between such paths, largely replacing \ with / and vice versa.
Convert between the formats.
1#include <liberate/fs/path.h>
2
3std::string posix_style{"/foo/bar"};
4
5auto win32_style = liberate::fs::to_win32_path(posix_style);
6auto back = liberate::fs::to_posix_path(win32_style);
7
8assert(posix_style == back);
Note
The liberate::fs::to_posix_path()
function is similar to the
generic_string() function of std::filesystem::path
, but works on
plain std::string
.