Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Get relative path from two absolute paths

I have two absolute filesystem paths (A and B), and I want to generate a third filesystem path that represents "A relative from B".

Use case:

  • Media player managing a playlist.
  • User adds file to playlist.
  • New file path added to playlist relative to playlist path.
  • In the future, entire music directory (including playlist) moved elsewhere.
  • All paths still valid because they are relative to the playlist.

boost::filesystem appears to have complete to resolve relative ~ relative => absolute, but nothing to do this in reverse (absolute ~ absolute => relative).

I want to do it with Boost paths.

Answer*

Cancel