Boost C++ Libraries: Ticket #6809: Implementation of filesystem::rename() method for MS Windows is wrong https://svn.boost.org/trac10/ticket/6809 <p> simple program: </p> <blockquote> <p> try { </p> <blockquote> <p> boost::filesystem::rename( "c:\1.txt", "d:\1.txt" ); </p> </blockquote> <p> } catch( boost::filesystem::filesystem_error&amp; e ) { </p> <blockquote> <p> std::cout &lt;&lt; "filesystem_error: " &lt;&lt; e.what(); </p> </blockquote> <p> } </p> </blockquote> <p> output: filesystem_error: boost::filesystem::rename: The system cannot move the file to a different disk drive: "c:\1.txt", "d:\1.txt" </p> <p> The problem is caused by BOOST_MOVE_FILE macro definition in \libs\filesystem\v3\src\operations.cpp file </p> <p> # define BOOST_MOVE_FILE(OLD,NEW)(::MoveFileExW(OLD, NEW, MOVEFILE_REPLACE_EXISTING)!= 0) </p> <p> According to MSDN: When moving a file, the destination can be on a different file system or volume. If the destination is on another drive, you must set the MOVEFILE_COPY_ALLOWED flag in dwFlags. </p> <p> Without this flag <a class="missing wiki">MoveFileEx</a>() method fails with error code 0x11 ("The system cannot move the file to a different disk drive"). </p> <p> So bug can be fixed in following way # define BOOST_MOVE_FILE(OLD,NEW)(::MoveFileExW(OLD, NEW, MOVEFILE_REPLACE_EXISTING|MOVEFILE_COPY_ALLOWED)!= 0) </p> <p> Please find a patch attached. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6809 Trac 1.4.3 Sergey Kazakov <sergeyyk@…> Thu, 19 Apr 2012 10:01:53 GMT attachment set https://svn.boost.org/trac10/ticket/6809 https://svn.boost.org/trac10/ticket/6809 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">libs_filesystem_src_operations.cpp.patch</span> </li> </ul> Ticket Beman Dawes Thu, 19 Apr 2012 12:45:45 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/6809#comment:1 https://svn.boost.org/trac10/ticket/6809#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">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/78078" title="Filesystem: Fix #6809, Implementation of filesystem::rename() method ...">[78078]</a>) Filesystem: Fix <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6809" title="#6809: Bugs: Implementation of filesystem::rename() method for MS Windows is wrong (closed: fixed)">#6809</a>, Implementation of filesystem::rename() method for MS Windows is wrong, by adding MOVEFILE_COPY_ALLOWED to deal with renames across drives, volumes, file systems. Fix has no effect on non-Windows systems. </p> Ticket