Suppose I have the following folder
std::string m("C:\MyFolderA\MyFolderB\MyFolderC");
boost::filesystem::path p(m);
Is there anyway for me to extract the parent of this folder. I want to get the string MyFolderB.
from the above path.
Suppose I have the following folder
std::string m("C:\MyFolderA\MyFolderB\MyFolderC");
boost::filesystem::path p(m);
Is there anyway for me to extract the parent of this folder. I want to get the string MyFolderB.
from the above path.
There is method parent_path, check the docs.
Or, if you prefer a string manipulation method.
#include <algorithm>
const std::string m("C:\\MyFolderA\\MyFolderB\\MyFolderC");
const std::string slash("\\");
auto last_slash(std::find_end(std::cbegin(m),
std::cend(m),
std::cbegin(slash),
std::cend(slash)));
auto second_to_last_slash(std::find_end(std::cbegin(m),
last_slash,
std::cbegin(slash),
std::cend(slash)));
const std::string parent(++second_to_last_slash, last_slash);
Live on Coliru, if you're into that.