| Technical Specification | ||||
| Filesystem library(filesystem TS) | ||||
| Library fundamentals(library fundamentals TS) | ||||
| Library fundamentals 2(library fundamentals TS v2) | ||||
| Library fundamentals 3(library fundamentals TS v3) | ||||
| Extensions for parallelism(parallelism TS) | ||||
| Extensions for parallelism 2(parallelism TS v2) | ||||
| Extensions for concurrency(concurrency TS) | ||||
| Extensions for concurrency 2(concurrency TS v2) | ||||
| Concepts(concepts TS) | ||||
| Ranges(ranges TS) | ||||
| Reflection(reflection TS) | ||||
| Mathematical special functions(special functions TR) | ||||
| Experimental Non-TS | ||||
| Pattern Matching | ||||
| Linear Algebra | ||||
| std::execution | ||||
| Contracts | ||||
| 2D Graphics |
| Classes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| File types | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Defined in header <experimental/filesystem> | ||
void copy(const path& from,const path& to); void copy(const path& from,const path& to, error_code& ec); | (1) | (filesystem TS) |
void copy(const path& from,const path& to, copy_options options); void copy(const path& from,const path& to, copy_options options, error_code& ec); | (2) | (filesystem TS) |
Copies files and directories, with a variety of options:
copy_options::none used asoptions.copy_file group, which is not relevant tocopy).The behavior is as follows:
copy_options::skip_symlinks orcopy_options::create_symlinks are present inoptions, by a call tosymlink_status).copy_options::skip_symlink is present inoptions, does nothing.copy_options::copy_symlinks is present inoptions, then behaves as ifcopy_symlink(from, to).copy_options::directories_only is present inoptions, does nothing.copy_options::create_symlinks is present inoptions, creates a symlink toto. Note:from must be an absolute path unlessto is in the current directory.copy_options::create_hard_links is present inoptions, creates a hard link toto.copy_options::recursive or iscopy_options::none.copy_options::none).Contents |
| 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 |
(none)
The default behavior when copying directories is the non-recursive copy: the files are copied, but not the subdirectories:
// Given// /dir1 contains /dir1/file1, /dir1/file2, /dir1/dir2// and /dir1/dir2 contains /dir1/dir2/file3// Afterstd::experimental::filesystem::copy("/dir1","/dir3");// /dir3 is created (with the attributes of /dir1)// /dir1/file1 is copied to /dir3/file1// /dir1/file2 is copied to /dir3/file2
While withcopy_options::recursive, the subdirectories are also copied, with their content, recursively.
// ...but afterstd::experimental::filesystem::copy("/dir1","/dir3", copy_options::recursive);// /dir3 is created (with the attributes of /dir1)// /dir1/file1 is copied to /dir3/file1// /dir1/file2 is copied to /dir3/file2// /dir3/dir2 is created (with the attributes of /dir1/dir2)// /dir1/dir2/file3 is copied to /dir3/dir2/file3
#include <experimental/filesystem>#include <fstream>#include <iostream>namespace fs= std::experimental::filesystem; int main(){ fs::create_directories("sandbox/dir/subdir");std::ofstream("sandbox/file1.txt").put('a'); fs::copy("sandbox/file1.txt","sandbox/file2.txt");// copy file fs::copy("sandbox/dir","sandbox/dir2");// copy directory (non-recursive)// sandbox holds 2 files and 2 directories, one of which has a subdirectory// sandbox/file1.txt// sandbox/file2.txt// sandbox/dir2// sandbox/dir// sandbox/dir/subdir fs::copy("sandbox","sandbox/copy", fs::copy_options::recursive);// sandbox/copy holds copies of the above files and subdirectories fs::remove_all("sandbox");}
| specifies semantics of copy operations (enum)[edit] | |
| copies a symbolic link (function)[edit] | |
| copies file contents (function)[edit] |