std::experimental::filesystem::copy (3) - Linux Man Pages
Defined in header <experimental/filesystem>
void copy( const path& from, const path& to ); (1) (filesystem TS)
void copy( const path& from, const path& to, error_code& ec );
void copy( const path& from, const path& to, copy_options options ); (2) (filesystem TS)
void copy( const path& from, const path& to, copy_options options, error_code& ec );
Copies files and directories, with a variety of options
1) The default, equivalent to (2) with copy_options::none used as options
2) Copies the file or directory from to file or directory 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 copy_file group, which is not relevant to copy)
The behavior is as follows:
* First, before doing anything else, obtains type and permissions of from by no more than single call to status (or, if copy_options::skip_symlinks or copy_options::create_symlinks are present in options, by a call to symlink_status).
* If necessary, obtains the status of to the same way, by no more than a single status or symlink_status call.
* If from does not exist, reports an error.
* If from and to are the same file as determined by equivalent(), reports an error
* If either from or to is not a regular file, a directory, or a symlink, as determined by is_other, reports an error
* If from is a directory, but to is a regular file, reports an error
* If from is a symbolic link, then
* Otherwise, if from is a regular file, then
* Otherwise, if from is a directory and either options has copy_options::recursive or is copy_options::none,
* Otherwise does nothing
from - path to the source file, directory, or symlink
to - path to the target file, directory, or symlink
ec - out-parameter for error reporting in the non-throwing overload
The overload that does not take a error_code& parameter throws filesystem_error on underlying OS API errors, constructed with from as the first argument, to as the second argument, and the OS error code as the error code argument. std::bad_alloc may be thrown if memory allocation fails. The overload taking a error_code& parameter sets it to the OS API error code if an OS API call fails, and executes ec.clear() if no errors occur. This overload has
The default behavior when copying directories is the non-recursive copy: the files are copied, but not the subdirectories:
While with copy_options::recursive, the subdirectories are also copied, with their content, recursively.
// Run this code