Tomado de un enlace que se encuentra siguiendo el billete Nicol vinculada a:
template < >
path& path::append< typename path::iterator >(typename path::iterator begin, typename path::iterator end, const codecvt_type& cvt)
{
for(; begin != end ; ++begin)
*this /= *begin;
return *this;
}
// Return path when appended to a_From will resolve to same as a_To
boost::filesystem::path make_relative(boost::filesystem::path a_From, boost::filesystem::path a_To)
{
a_From = boost::filesystem::absolute(a_From); a_To = boost::filesystem::absolute(a_To);
boost::filesystem::path ret;
boost::filesystem::path::const_iterator itrFrom(a_From.begin()), itrTo(a_To.begin());
// Find common base
for(boost::filesystem::path::const_iterator toEnd(a_To.end()), fromEnd(a_From.end()) ; itrFrom != fromEnd && itrTo != toEnd && *itrFrom == *itrTo; ++itrFrom, ++itrTo);
// Navigate backwards in directory to reach previously found base
for(boost::filesystem::path::const_iterator fromEnd(a_From.end()); itrFrom != fromEnd; ++itrFrom)
{
if((*itrFrom) != ".")
ret /= "..";
}
// Now navigate down the directory branch
ret.append(itrTo, a_To.end());
return ret;
}
Stick que en un archivo de cabecera y debe hacer lo que quiera.
llamada de ejemplo: Código
boost::filesystem::path a("foo/bar"), b("foo/test/korv.txt");
std::cout << make_relative(a, b).string() << std::endl;
Todo lo demás falla, convierta ambos en cadenas absolutas y subcadenas una de la otra. –
Las nuevas versiones de boost tienen una respuesta ** muy simple **, siempre que [abajo] (https://stackoverflow.com/a/37715252/16287) –