std::filesystem::copy_file
From cppreference.com
< cpp | filesystem
Defined in header <filesystem>
|
||
bool copy_file( const std::filesystem::path& from, const std::filesystem::path& to ); |
(1) | (since C++17) |
bool copy_file( const std::filesystem::path& from, const std::filesystem::path& to, |
(2) | (since C++17) |
bool copy_file( const std::filesystem::path& from, const std::filesystem::path& to, |
(3) | (since C++17) |
bool copy_file( const std::filesystem::path& from, const std::filesystem::path& to, |
(4) | (since C++17) |
1,2) The default, equivalent to (3,4) with
copy_options::none
used as options.3,4) Copies a single file from from to to, using the copy options indicated by options. The behavior is undefined if there is more than one option in any of the copy_options option group present in options (even in the groups not relevant to filesystem::copy_file).
- If !filesystem::is_regular_file(from) (either because the source file doesn't exist or because it is not a regular file), report an error.
- Otherwise, if the destination file does not exist,
- copies the contents and the attributes of the file to which from resolves to the file to which to resolves (symlinks are followed).
- Otherwise, if the destination file already exists,
- report an error if any of the following is true:
- to and from are the same as determined by filesystem::equivalent(from, to);
- to is not a regular file as determined by !filesystem::is_regular_file(to);
- none of the filesystem::copy_file control options are set in options.
- Otherwise, if
copy_options::skip_existing
is set in options, do nothing. - Otherwise, if
copy_options::overwrite_existing
is set in options, copy the contents and the attributes of the file to which from resolves to the file to which to resolves. - Otherwise, if
copy_options::update_existing
is set in options, only copy the file if from is newer than to, as defined by filesystem::last_write_time().
The non-throwing overloads return false if an error occurs.
Contents |
[edit] Parameters
from | - | path to the source file |
to | - | path to the target file |
ec | - | out-parameter for error reporting in the non-throwing overload |
[edit] Return value
true if the file was copied, false otherwise.
[edit] Exceptions
Any overload not marked noexcept
may throw std::bad_alloc if memory allocation fails.
1,3) Throws