std::experimental::filesystem::copy_options (3) - Linux Manuals

std::experimental::filesystem::copy_options: std::experimental::filesystem::copy_options


std::experimental::filesystem::copy_options - std::experimental::filesystem::copy_options


Defined in header <experimental/filesystem>
enum class copy_options {
none = 0,
skip_existing = 1,
overwrite_existing = 2,
update_existing = 4,
recursive = 8, (filesystem TS)
copy_symlinks = 16,
skip_symlinks = 32,
directories_only = 64,
create_symlinks = 128,
create_hard_links = 256

This type represents available options that control the behavior of the copy() and copy_file() function.
copy_options satisfies the requirements of BitmaskType (which means the bitwise operators operator&, operator|, operator^, operator~, operator&=, operator|=, and operator^= are defined for this type)

Member constants

At most one copy option in each of the following options groups may be present, otherwise the behavior of the copy functions is undefined.

Member constant Value Meaning
options controlling copy_file() when the file already exists
skip_existing 1 Keep the existing file, without reporting an error.
overwrite_existing 2 Replace the existing file
update_existing 4 Replace the existing file only if it is older than the file being copied
options controlling the effects of copy() on subdirectories
recursive 8 Recursively copy subdirectories and their content
options controlling the effects of copy() on symbolic links
copy_symlinks 16 Copy symlinks as symlinks, not as the files they point to
skip_symlinks 32 Ignore symlinks
options controlling the kind of copying copy() does
directories_only 64 Copy the directory structure, but do not copy any non-directory files
create_symlinks 128 Instead of creating copies of files, create symlinks pointing to the originals. Note: the source path must be an absolute path unless the destination path is in the current directory.
create_hard_links 256 Instead of creating copies of files, create hardlinks that resolve to the same files as the originals


// Run this code

  #include <iostream>
  #include <fstream>
  #include <experimental/filesystem>
  namespace fs = std::experimental::filesystem;

  int main()
      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

See also

          copies files or directories
copy (function)
          copies file contents
copy_file (function)