Question

I've got some older versions of boost code that uses the member function leaf() of the path class in the boost filesystem library. However, when trying to compile it recently, I've noticed this has disappeared and deprecated.

The task it is doing is getting all the directories that are in a specified folder and storing them.

For the sake of this example, let's just say I was outputting them to the console.

For the example, the directories could be:

/home/user/dir/

/home/user/dir/one

/home/user/dir/two

/hone/user/dir/three

So I pass in /home/user/dir into a directory_iterator and check if it's a directory using is_directory(). What I would like would be to print the last part of the paths, so...

one
two
three

I know I could do some string manipulation to do this by searching for the last / etc. but I would like to know if there is still a way to do this using the path class.

Was it helpful?

Solution

As I can read from the Boost documentation, the leaf() method has been replaced with filename(). You can get all the elements using iterators. More in Boost Filesystem Tutorial, including working example of usage.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top