[filesystem] relative path from arbitrary file system location?

Is there any existing functionality for getting a relative path from a full path, where the desired relative path is relative to an arbitrary directory path? If not, I'm assuming I would just have to walk up both full paths until I find their intersection...etc

On Fri, Feb 6, 2009 at 21:22, Kenny Riddile <kfriddile@yahoo.com> wrote:
Is there any existing functionality for getting a relative path from a full path, where the desired relative path is relative to an arbitrary directory path? If not, I'm assuming I would just have to walk up both full paths until I find their intersection...etc
There isn't yet, though I have a ticket filed requesting one: https://svn.boost.org/trac/boost/ticket/1976 Please add your use case to that ticket. The v3 lib under discussion has a read_symlink function which will allow a non-naïve implementation. In the mean time, if you're in windows you can try the implementation in the ticket.

Scott McMurray wrote:
On Fri, Feb 6, 2009 at 21:22, Kenny Riddile <kfriddile@yahoo.com> wrote:
Is there any existing functionality for getting a relative path from a full path, where the desired relative path is relative to an arbitrary directory path? If not, I'm assuming I would just have to walk up both full paths until I find their intersection...etc
There isn't yet, though I have a ticket filed requesting one: https://svn.boost.org/trac/boost/ticket/1976 Please add your use case to that ticket.
The v3 lib under discussion has a read_symlink function which will allow a non-naïve implementation. In the mean time, if you're in windows you can try the implementation in the ticket. _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Thanks. The use case proposed on your ticket is literally identical to mine (persisting relative paths to allow checking output files in subversion).

Scott McMurray wrote:
On Fri, Feb 6, 2009 at 21:22, Kenny Riddile <kfriddile@yahoo.com> wrote:
Is there any existing functionality for getting a relative path from a full path, where the desired relative path is relative to an arbitrary directory path? If not, I'm assuming I would just have to walk up both full paths until I find their intersection...etc
There isn't yet, though I have a ticket filed requesting one: https://svn.boost.org/trac/boost/ticket/1976 Please add your use case to that ticket.
The v3 lib under discussion has a read_symlink function which will allow a non-naïve implementation. In the mean time, if you're in windows you can try the implementation in the ticket. _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Also, may I suggest the name "as_relative_to" for the member function if this is added to the library? as_relative_to would be a const member method that take the desired base path as its only parameter and returns the desired relative path.

On Fri, Feb 6, 2009 at 22:32, Kenny Riddile <kfriddile@yahoo.com> wrote:
Also, may I suggest the name "as_relative_to" for the member function if this is added to the library? as_relative_to would be a const member method that take the desired base path as its only parameter and returns the desired relative path.
The problem I see with that is that to handle symlinks elegantly, "uncomplete" will need to look at the filesystem, not just the path elements, which, following as I understand the way things are organized, prevents it from being part of the path class itself. (This is the same problem that keeps coming up: ./foo/bar/.. doesn't have to be ./foo when symlinks are involved.) In any case, it's the inverse function to complete, so it should be the same kind of beast. (It seems p.has_root_path() ? complete(relative(p)) : relative(complete(p)) should be equivalent to p, assuming compatible root_name()s in the first branch.) As I mention in the ticket, I really like the idea of calling the function relative, but I'm worried about conceptual conflict with the relative_path() decomposition function (which I don't really like, since if complete uses initial_path, it seems like relative would be to initial_path, not to the root of the path in question, though the member/nonmember may be enough to disambiguate).
participants (2)
-
Kenny Riddile
-
Scott McMurray