Boost C++ Libraries: Ticket #2260: Missing slash when iterating windows root path https://svn.boost.org/trac10/ticket/2260 <p> A windows root path without backslash or slash, ex. "C:", will cause the result of directory_iterator missing a slash after ':'. For example, it will produce a broken path such as "C:filename". </p> <p> Here is a sample to produce this: </p> <pre class="wiki">#include &lt;iostream&gt; #include &lt;locale&gt; #include &lt;boost/filesystem.hpp&gt; using namespace boost::filesystem; int main() { const char *drive_to_search = "C:"; std::cout.imbue( std::locale()); for( directory_iterator i( path( drive_to_search, native)), end; i != end; ++i) { std::cout &lt;&lt; i-&gt;path() &lt;&lt; std::endl; } return 0; } </pre><p> By tracing the stack, I think the problem is function boost::filesystem::basic_path&lt;std::basic_string&lt;wchar_t,std::char_traits&lt;wchar_t&gt;,std::allocator&lt;wchar_t&gt; &gt;,boost::filesystem::wpath_traits&gt;::m_append_separator_if_needed() won't append a slash in case of merging windows root path and filename. </p> <p> Here is the call stack starting at the constructor of directory_iterator. </p> <pre class="wiki">boost::filesystem::basic_path&lt;std::basic_string&lt;wchar_t,std::char_traits&lt;wchar_t&gt;,std::allocator&lt;wchar_t&gt; &gt;,boost::filesystem::wpath_traits&gt;::m_append_separator_if_needed() boost::filesystem::basic_path&lt;std::basic_string&lt;wchar_t,std::char_traits&lt;wchar_t&gt;,std::allocator&lt;wchar_t&gt; &gt;,boost::filesystem::wpath_traits&gt;::operator/=(const wchar_t *) boost::filesystem::basic_path&lt;std::basic_string&lt;wchar_t,std::char_traits&lt;wchar_t&gt;,std::allocator&lt;wchar_t&gt; &gt;,boost::filesystem::wpath_traits&gt;::operator/=(const boost::filesystem::basic_path&lt;std::basic_string&lt;wchar_t,std::char_traits&lt;wchar_t&gt;,std::allocator&lt;wchar_t&gt; &gt;,boost::filesystem::wpath_traits&gt; &amp; rhs) boost::filesystem::operator/&lt;std::basic_string&lt;wchar_t,std::char_traits&lt;wchar_t&gt;,std::allocator&lt;wchar_t&gt; &gt;,boost::filesystem::wpath_traits&gt;(const boost::filesystem::basic_path&lt;std::basic_string&lt;wchar_t,std::char_traits&lt;wchar_t&gt;,std::allocator&lt;wchar_t&gt; &gt;,boost::filesystem::wpath_traits&gt; &amp; lhs, const std::basic_string&lt;wchar_t,std::char_traits&lt;wchar_t&gt;,std::allocator&lt;wchar_t&gt; &gt; &amp; rhs) boost::filesystem::basic_directory_iterator&lt;boost::filesystem::basic_path&lt;std::basic_string&lt;wchar_t,std::char_traits&lt;wchar_t&gt;,std::allocator&lt;wchar_t&gt; &gt;,boost::filesystem::wpath_traits&gt; &gt;::m_init(const boost::filesystem::basic_path&lt;std::basic_string&lt;wchar_t,std::char_traits&lt;wchar_t&gt;,std::allocator&lt;wchar_t&gt; &gt;,boost::filesystem::wpath_traits&gt; &amp; dir_path) boost::filesystem::basic_directory_iterator&lt;boost::filesystem::basic_path&lt;std::basic_string&lt;wchar_t,std::char_traits&lt;wchar_t&gt;,std::allocator&lt;wchar_t&gt; &gt;,boost::filesystem::wpath_traits&gt; &gt;::basic_directory_iterator&lt;boost::filesystem::basic_path&lt;std::basic_string&lt;wchar_t,std::char_traits&lt;wchar_t&gt;,std::allocator&lt;wchar_t&gt; &gt;,boost::filesystem::wpath_traits&gt; &gt;(const boost::filesystem::basic_path&lt;std::basic_string&lt;wchar_t,std::char_traits&lt;wchar_t&gt;,std::allocator&lt;wchar_t&gt; &gt;,boost::filesystem::wpath_traits&gt; &amp; dir_path) </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2260 Trac 1.4.3 Beman Dawes Mon, 12 Jan 2009 00:33:21 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2260#comment:1 https://svn.boost.org/trac10/ticket/2260#comment:1 <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">invalid</span> </li> </ul> <p> "C:filename" is perfectly valid. Windows interprets the directory as being the current working directory on the C drive. This is demonstrated from the command line by: </p> <blockquote class="citation"> <p> dir </p> </blockquote> <blockquote> <p> Volume in drive C has no label. Volume Serial Number is D4A2-EC0D </p> </blockquote> <blockquote> <p> Directory of C:\boost\trunk\libs\filesystem\test\msvc\ticket_2260_test </p> </blockquote> <p> 01/11/2009 07:05 PM &lt;DIR&gt; . 01/11/2009 07:05 PM &lt;DIR&gt; .. 01/11/2009 07:12 PM &lt;DIR&gt; Debug 01/11/2009 07:05 PM 4,070 ticket_2260_test.vcproj 01/11/2009 07:15 PM 1,409 ticket_2260_test.vcproj.BGD.Administrator.user </p> <blockquote> <p> 2 File(s) 5,479 bytes 3 Dir(s) 210,340,593,664 bytes free </p> </blockquote> <blockquote class="citation"> <p> dir c: </p> </blockquote> <blockquote> <p> Volume in drive C has no label. Volume Serial Number is D4A2-EC0D </p> </blockquote> <blockquote> <p> Directory of C:\boost\trunk\libs\filesystem\test\msvc\ticket_2260_test </p> </blockquote> <p> 01/11/2009 07:05 PM &lt;DIR&gt; . 01/11/2009 07:05 PM &lt;DIR&gt; .. 01/11/2009 07:12 PM &lt;DIR&gt; Debug 01/11/2009 07:05 PM 4,070 ticket_2260_test.vcproj 01/11/2009 07:15 PM 1,409 ticket_2260_test.vcproj.BGD.Administrator.user </p> <blockquote> <p> 2 File(s) 5,479 bytes 3 Dir(s) 210,340,626,432 bytes free </p> </blockquote> <p> Note the way that "dir c:" works. </p> <p> If you want C:\ rather than the current C: directory, change line 10 to: </p> <p> const char *drive_to_search = "C:<br />"; </p> <p> --Beman </p> Ticket