Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

std(boost)::filesystem::path number of components

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?

like image 796
ledonter Avatar asked Nov 23 '25 15:11

ledonter


1 Answers

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());
like image 68
Sam Markus Avatar answered Nov 25 '25 06:11

Sam Markus