Subject: [Boost-bugs] [Boost C++ Libraries] #5897: Make path relative function.
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-09-13 22:51:59
#5897: Make path relative function.
---------------------------------+------------------------------------------
Reporter: jmckesson@⦠| Owner: bemandawes
Type: Feature Requests | Status: new
Milestone: To Be Determined | Component: filesystem
Version: Boost 1.47.0 | Severity: Problem
Keywords: |
---------------------------------+------------------------------------------
It is often useful to take a path that is absolute and make it relative to
some other path. For example, if you're copying from directory A to
directory B using a recursive_directory_iterator, it is often the case
that you will do the following:
{{{
for_each(bfs::recursive_directory_iterator(directoryA),
bfs::recursive_directory_iterator(), [=](const bfs::directory_entry
&entry)
{
if(bfs::is_file(entry.status()))
{
bfs::path dstPath = directoryB / make_relative(directoryA,
entry.path());
bfs::copy_file(entry.path(), dstPath);
}
});
}}}
The `make_relative` function would iterate through the path components of
the two arguments, removing entries until it found different ones. Then,
it would add ".." to the beginning of the second path argument, until it
ran out of directories in the first path. What you are left with is the
second path relative to the first one.
Obviously, this would not work if both paths are absolute. But this is
such a common operation that there has to be some way to make it work.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/5897> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:07 UTC