29 Input/output library [input.output]

29.11 File systems [filesystems]

29.11.14 Filesystem operation functions [fs.op.funcs]

29.11.14.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);
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);
Preconditions: At most one element from each option group ([fs.enum.copy.opts]) is set in options.
Effects: As follows:
  • Report an error as specified in [fs.err.report] if:
    • is_­regular_­file(from) is false, or
    • exists(to) is true and is_­regular_­file(to) is false, or
    • exists(to) is true and equivalent(from, to) is true, or
    • exists(to) is true 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) is false, 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).