27 Input/output library [input.output]

27.10 File systems [filesystems]

27.10.15 Filesystem operation functions [fs.op.funcs]

27.10.15.4 Copy file [fs.op.copy_file]

bool copy_file(const path& from, const path& to); bool copy_file(const path& from, const path& to, error_code& ec) noexcept;

Returns: copy_file(from, to, copy_options::none) or
copy_file(from, to, copy_options::none, ec), respectively.

Throws: As specified in [fs.err.report].

bool copy_file(const path& from, const path& to, copy_options options); bool copy_file(const path& from, const path& to, copy_options options, error_code& ec) noexcept;

Requires: At most one constant from each copy_options option group ([enum.copy_options]) is present in options.

Effects: As follows:

  • Report a file already exists error as specified in [fs.err.report] if:

    • !is_regular_file(from), or

    • exists(to) and !is_regular_file(to), or

    • exists(to) and equivalent(from, to), or

    • exists(to) and (options & (copy_options::skip_existing | copy_options::overwrite_existing | copy_options::update_existing)) == copy_options::none.

  • Otherwise, copy the contents and attributes of the file from resolves to, to the file to resolves to, if:

    • !exists(to), or

    • exists(to) and (options & copy_options::overwrite_existing) != copy_options::none, or

    • exists(to) and (options & copy_options::update_existing) != copy_options::none and from is more recent than to, determined as if by use of the last_write_time function ([fs.op.last_write_time]).

  • Otherwise, no effects.

Returns: true if the from file was copied, otherwise false. The signature with argument ec returns false if an error occurs.

Throws: As specified in [fs.err.report].

Complexity: At most one direct or indirect invocation of status(to).