Boost C++ Libraries: Ticket #5897: Make path relative function. https://svn.boost.org/trac10/ticket/5897 <p> 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: </p> <pre class="wiki">for_each(bfs::recursive_directory_iterator(directoryA), bfs::recursive_directory_iterator(), [=](const bfs::directory_entry &amp;entry) { if(bfs::is_file(entry.status())) { bfs::path dstPath = directoryB / make_relative(directoryA, entry.path()); bfs::copy_file(entry.path(), dstPath); } }); </pre><p> The <code>make_relative</code> 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. </p> <p> 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. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5897 Trac 1.4.3 anonymous Mon, 21 Nov 2011 01:35:11 GMT <link>https://svn.boost.org/trac10/ticket/5897#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5897#comment:1</guid> <description> <p> Great idea! I was looking for that exact function just today. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 13 Dec 2011 13:30:03 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5897#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5897#comment:2</guid> <description> <p> I've added an example for 1.46.1 ( probably works for trunk as well, haven't tried ). For details take a look at <a class="ext-link" href="https://svn.boost.org/trac/boost/ticket/6249"><span class="icon">​</span>https://svn.boost.org/trac/boost/ticket/6249</a> . </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 26 Jul 2013 07:48:51 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5897#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5897#comment:3</guid> <description> <p> Please consider this feature, it is required rather often - <a class="ext-link" href="http://stackoverflow.com/questions/10167382/boostfilesystem-get-relative-path"><span class="icon">​</span>http://stackoverflow.com/questions/10167382/boostfilesystem-get-relative-path</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 30 Jul 2013 07:09:30 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5897#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5897#comment:4</guid> <description> <p> This would be really helpful, I'd consider it one of the basic functions you want to do with paths. </p> </description> <category>Ticket</category> </item> <item> <author>slowriot <riot@…></author> <pubDate>Sat, 15 Nov 2014 15:54:08 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5897#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5897#comment:5</guid> <description> <p> +1 for this. </p> </description> <category>Ticket</category> </item> <item> <author>mojes@…</author> <pubDate>Sun, 23 Nov 2014 20:32:30 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5897#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5897#comment:6</guid> <description> <p> +1 for this </p> </description> <category>Ticket</category> </item> <item> <author>fhntv24fhntv24@…</author> <pubDate>Mon, 15 Dec 2014 22:29:51 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5897#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5897#comment:7</guid> <description> <p> +1 for this. </p> </description> <category>Ticket</category> </item> <item> <author>londinop@…</author> <pubDate>Fri, 20 Feb 2015 00:47:32 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5897#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5897#comment:8</guid> <description> <p> +1 for this. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 23 Mar 2015 10:39:27 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5897#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5897#comment:9</guid> <description> <p> +1 </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 24 Mar 2015 11:05:46 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5897#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5897#comment:10</guid> <description> <p> +1 </p> </description> <category>Ticket</category> </item> <item> <dc:creator>jarruda</dc:creator> <pubDate>Wed, 29 Apr 2015 06:22:05 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5897#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5897#comment:11</guid> <description> <p> Could a contributor at least comment on this? This at least seems like a "must-have" feature for any utility file system API. 4 years is a pretty long time for a simple feature request to not be acknowledged. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 29 Apr 2015 18:17:32 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5897#comment:12 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5897#comment:12</guid> <description> <p> Have you not seen the other 2692 active tickets they're equally busy ignoring? ;) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Beman Dawes</dc:creator> <pubDate>Sat, 05 Sep 2015 18:32:42 GMT</pubDate> <title>status, milestone changed; resolution set https://svn.boost.org/trac10/ticket/5897#comment:13 https://svn.boost.org/trac10/ticket/5897#comment:13 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.60.0</span> </li> </ul> <p> Boost 1.60.0 will add functions lexically_normal, lexically_relative, relative, and weakly_canonical. These are designed to provide the functionality requested by this ticket. </p> <p> See <a class="ext-link" href="http://boostorg.github.io/filesystem/relative_proposal.html"><span class="icon">​</span>http://boostorg.github.io/filesystem/relative_proposal.html</a> for more information. It proposes additional lexical and operational proximate functions, but I have chosen not to include those now. They will be reconsidered once users get some field experience with the core functionality for computing relative paths. </p> <p> These function are available now on the <a class="ext-link" href="https://github.com/boostorg/filesystem"><span class="icon">​</span>https://github.com/boostorg/filesystem</a> develop branch, and will be merged to master as soon as sufficient regression tests have cycled. They will also be proposed for inclusion in the next version of the C++ committee's TS 18822, File System Technical Specification. </p> <p> Many thanks to Jamie Allsop for his help and perseverance, and to everyone else who made suggestions and comments. Jamie's paper is available at <a class="ext-link" href="https://github.com/ja11sop/std-filesystem-relative"><span class="icon">​</span>https://github.com/ja11sop/std-filesystem-relative</a> </p> <p> Thanks, </p> <p> --Beman </p> Ticket