Boost C++ Libraries: Ticket #361: patch for boost::filesystem https://svn.boost.org/trac10/ticket/361 <pre class="wiki">hi, when you try to get the branch path of this "c:\\some_dir\\some_file.txt" under windows the branch path should be "c:\\some_dir". what is returned instead is "c:" which isn't correct. so here's the fix: in path_posix_windows.cpp: std::string::size_type leaf_pos( const std::string &amp; str, std::string::size_type end_pos ) // end_pos is past-the-end position // return 0 if str itself is leaf (or empty) { if ( end_pos &amp;&amp; str[end_pos-1] == '/' ) return end_pos-1; std::string::size_type pos( str.find_last_of( '/', end_pos-1 ) ); # ifdef BOOST_WINDOWS if ( pos == std::string::npos ) pos = str.find_last_of( '\\', end_pos-1 ); // ADDED if ( pos == std::string::npos ) pos = str.find_last_of( ':', end_pos-2 ); # endif return ( pos == std::string::npos // path itself must be a leaf (or empty) # ifdef BOOST_WINDOWS || (pos == 1 &amp;&amp; (str[0] == '/' || str[0] == '\\')) // or share // ADDED # endif ) ? 0 // so leaf is entire string : pos + 1; // or starts after delimiter } mfg steven </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/361 Trac 1.4.3 fotzor Sat, 05 Mar 2005 08:24:11 GMT <link>https://svn.boost.org/trac10/ticket/361#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/361#comment:1</guid> <description> <pre class="wiki">Logged In: YES user_id=1124235 i forgot something... in branch_path() you must also change the condition of the if to: if ( end_pos &amp;&amp; (m_path[end_pos-1] == '/' || m_path[end_pos-1] == '\\') &amp;&amp; !detail::is_absolute_root( m_path, end_pos ) ) --end_pos; else it doesn't work proper. perhaps there are other functions depending on leaf_pos() that must be adjusted as well </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>biochimia</dc:creator> <pubDate>Sat, 04 Feb 2006 06:18:26 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/361#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/361#comment:2</guid> <description> <pre class="wiki">Logged In: YES user_id=840777 The claim appears to be wrong. The test program below works with Boost 1.32, the last release at the time of the original report. Also works with 1.33.1 and the i18n update in current CVS. Exploring a bit deeper it seems the OP might be using no_check for the name check, in which case '\\' is not necessarily a valid separator character according to the portable grammar. The i18n branch fixes the issue even when using no_check. I'm setting the patch as invalid. I suppose it could be closed/deleted. #include &lt;boost/filesystem/path.hpp&gt; #include &lt;cassert&gt; namespace fs = boost::filesystem; int main() { fs::path const path1("c:\\some_dir\\some_file.txt", fs::native), path2("c:\\some_dir", fs::native), path3("c:", fs::native); assert(path1.branch_path() == path2); assert(path1.branch_path() != path3); } </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>beman_dawes</dc:creator> <pubDate>Tue, 07 Feb 2006 23:52:24 GMT</pubDate> <title>status changed https://svn.boost.org/trac10/ticket/361#comment:3 https://svn.boost.org/trac10/ticket/361#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> </ul> <pre class="wiki">Logged In: YES user_id=51042 Could not reproduce. Added path regression test cases. They pass. Closing without action. </pre> Ticket