[fs.op.copy.file]

# 31 Input/output library [[input.output]](./#input.output)

## 31.12 File systems [[filesystems]](filesystems#fs.op.copy.file)

### 31.12.13 Filesystem operation functions [[fs.op.funcs]](fs.op.funcs#fs.op.copy.file)

#### 31.12.13.5 Copy file [fs.op.copy.file]

[ð](#lib:copy_file)

`bool filesystem::copy_file(const path& from, const path& to);
bool filesystem::copy_file(const path& from, const path& to, error_code& ec);
`

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L17439)

*Returns*: copy_file(from, to, copy_options​::​none) or  

copy_file(from, to, copy_options​::​none, ec), respectively[.](#1.sentence-2)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L17444)

*Throws*: As specified in [[fs.err.report]](fs.err.report "31.12.5 Error reporting")[.](#2.sentence-1)

[ð](#lib:copy_file_)

`bool filesystem::copy_file(const path& from, const path& to, copy_options options);
bool filesystem::copy_file(const path& from, const path& to, copy_options options,
                           error_code& ec);
`

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L17457)

*Preconditions*: At most one element from each
option group ([[fs.enum.copy.opts]](fs.enum.copy.opts "31.12.8.3 Enum class copy_­options")) is set
in options[.](#3.sentence-1)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L17463)

*Effects*: As follows:

- [(4.1)](#4.1)

  Report an error as specified in [[fs.err.report]](fs.err.report "31.12.5 Error reporting") if
  * [(4.1.1)](#4.1.1)

is_regular_file(from) is false, or

  * [(4.1.2)](#4.1.2)

exists(to) is true and is_regular_file(to) is false, or

  * [(4.1.3)](#4.1.3)

exists(to) is true and equivalent(from, to) is true, or

  * [(4.1.4)](#4.1.4)

exists(to) is true and(options & (copy_options::skip_existing | copy_options::overwrite_existing | copy_options::update_existing)) == copy_options::none

- [(4.2)](#4.2)

  Otherwise, copy the contents and attributes of the file from resolves to, to the file to resolves to, if
  * [(4.2.1)](#4.2.1)

exists(to) is false, or

  * [(4.2.2)](#4.2.2)

(options & copy_options​::​overwrite_existing) != copy_options​::​none, or

  * [(4.2.3)](#4.2.3)

(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]](fs.op.last.write.time "31.12.13.26 Last write time"))[.](#4.2.sentence-1)

- [(4.3)](#4.3)

  Otherwise, no effects[.](#4.3.sentence-1)

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L17495)

*Returns*: true if the from file
 was copied, otherwise false[.](#5.sentence-1)

The signature with argument ec returns false if an error occurs[.](#5.sentence-2)

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L17501)

*Throws*: As specified in [[fs.err.report]](fs.err.report "31.12.5 Error reporting")[.](#6.sentence-1)

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L17505)

*Complexity*: At most one direct or indirect invocation of status(to)[.](#7.sentence-1)
