std::filesystem::rename - cppreference.com (original) (raw)

Defined in header
void rename( const std::filesystem::path& old_p, const std::filesystem::path& new_p ); (1) (since C++17)
void rename( const std::filesystem::path& old_p, const std::filesystem::path& new_p, std::error_code& ec ) noexcept; (2) (since C++17)

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

Rename fails if

[edit] Parameters

old_p - path to move or rename
new_p - target path for the move/rename operation
ec - out-parameter for error reporting in the non-throwing overload

[edit] Return value

(none)

[edit] Exceptions

Any overload not marked noexcept may throw std::bad_alloc if memory allocation fails.

  1. Throws std::filesystem::filesystem_error on underlying OS API errors, constructed with old_p as the first path argument, new_p as the second path argument, and the OS error code as the error code argument.

  2. Sets a std::error_code& parameter to the OS API error code if an OS API call fails, and executes ec.clear() if no errors occur.

[edit] Example

[edit] See also

| | renames a file (function) [edit] | | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | | removes a file or empty directoryremoves a file or directory and all its contents, recursively (function) [edit] |