Reputation: 1719
Is there any idiomatic way to get number of components in a path using filesystem library? Or have I missed some method for this?
Or do I have to, like, call parent_path()
until I get to the root?
Upvotes: 2
Views: 1214
Reputation: 320
How about the size()
method?
boost::filesystem::path p;
// fill p
std::cout << p.size() << std::endl;
will give you the number of components.
Also path
iterators don't iterate over the string of the path, but over the components of the path. So this should work too:
std::distance(p.begin(), p.end());
Upvotes: 1