30 Input/output library [input.output]

30.10 File systems [filesystems]

30.10.34 Filesystem operation functions [fs.op.funcs]

30.10.34.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 element from each option group ([fs.enum.copy.opts]) is set 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

    • (options & copy_­options​::​overwrite_­existing) != copy_­options​::​none, or

    • (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).