Search code examples
c++move

Is there an <experimental/filesystem> move operation I am missing?


Is there a move() function I am missing? Best I have come up with is a hardlinked copy followed by delete original, but it doesn't fill me with confidence having to manually manage the two operations, nor does it work across filesystems.


Solution

  • It is not called move but rename.

    std::filesystem::rename

    Moves or renames the filesystem object identified by old_p to new_p as if by the POSIX rename

     void rename(const std::filesystem::path& old_p,
                 const std::filesystem::path& new_p);
    
     void rename(const std::filesystem::path& old_p,  // (since C++17)
                 const std::filesystem::path& new_p,
                 std::error_code& ec) noexcept;