I'm working with C++17 on Windows. As far as I can see, std::filesystem
doesn't have an is_root()
function or something similar that tells me if a path refers directly to C: or D: or any other volumen. Am I missing something?
Currently I'm doing this:
if (path.parent_path() == path)
{
//
}
It looks like it's working, but I don't know if this misses any edge cases. Is there a better way?
EDIT:
I want to check if the entirety of the path is just the volume name (maybe followed by an optional slash or backslash).
So, if there was a function like this, I'd like it to behave as follows:
namespace fs = std::filesystem;
is_root(fs::path{ "C:" }); // true
is_root(fs::path{ "D:\\"}); // true
is_root(fs::path{ "C:/users" }) // false
is_root(fs::current_path()) // usually false, unless the executable was started directly in C: or D: or any other drive