Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::filesystem::copy_options

      From cppreference.com
      <cpp‎ |filesystem
       
       
      Filesystem library
      Classes
      Functions
      File types
       
      Defined in header<filesystem>
      enumclass copy_options{

          none=/* unspecified */,
          skip_existing=/* unspecified */,
          overwrite_existing=/* unspecified */,
          update_existing=/* unspecified */,
          recursive=/* unspecified */,
          copy_symlinks=/* unspecified */,
          skip_symlinks=/* unspecified */,
          directories_only=/* unspecified */,
          create_symlinks=/* unspecified */,
          create_hard_links=/* unspecified */

      };
      (since C++17)

      This type represents available options that control the behavior of thecopy() andcopy_file() function.

      copy_options satisfies the requirements ofBitmaskType (which means the bitwise operatorsoperator&,operator|,operator^,operator~,operator&=,operator|=, andoperator^= are defined for this type).none represents the empty bitmask; every other enumerator represents a distinct bitmask element.

      [edit]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 constantMeaning
      options controllingcopy_file() when the file already exists
      noneReport an error (default behavior).
      skip_existingKeep the existing file, without reporting an error.
      overwrite_existingReplace the existing file.
      update_existingReplace the existing file only if it is older than the file being copied.
      options controlling the effects ofcopy() on subdirectories
      noneSkip subdirectories (default behavior).
      recursiveRecursively copy subdirectories and their content.
      options controlling the effects ofcopy() on symbolic links
      noneFollow symlinks (default behavior).
      copy_symlinksCopy symlinks as symlinks, not as the files they point to.
      skip_symlinksIgnore symlinks.
      options controlling the kind of copyingcopy() does
      noneCopy file content (default behavior).
      directories_onlyCopy the directory structure, but do not copy any non-directory files.
      create_symlinksInstead 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_linksInstead of creating copies of files, create hardlinks that resolve to the same files as the originals.

      [edit]Example

      Run this code
      #include <cstdlib>#include <filesystem>#include <fstream>#include <iostream>namespace fs= std::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)constauto copyOptions= fs::copy_options::update_existing| fs::copy_options::recursive| fs::copy_options::directories_only;    fs::copy("sandbox","sandbox_copy", copyOptions);static_cast<void>(std::system("tree"));    fs::remove_all("sandbox");    fs::remove_all("sandbox_copy");}

      Possible output:

      .├── sandbox│   ├── dir│   │   └── subdir│   ├── dir2│   ├── file1.txt│   └── file2.txt└── sandbox_copy    ├── dir    │   └── subdir    └── dir2 8 directories, 2 files

      [edit]See also

      (C++17)
      copies files or directories
      (function)[edit]
      (C++17)
      copies file contents
      (function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/filesystem/copy_options&oldid=157912"

      [8]ページ先頭

      ©2009-2025 Movatter.jp