std::filesystem::copy_options (3) - Linux Manuals
std::filesystem::copy_options: std::filesystem::copy_options
Command to display std::filesystem::copy_options
manual in Linux: $ man 3 std::filesystem::copy_options
NAME
std::filesystem::copy_options - std::filesystem::copy_options
Synopsis
Defined in header <filesystem>
enum class copy_options {
none = /* unspecified */,
skip_existing = /* unspecified */,
overwrite_existing = /* unspecified */,
update_existing = /* unspecified */,
recursive = /* unspecified */, (since C++17)
copy_symlinks = /* unspecified */,
skip_symlinks = /* unspecified */,
directories_only = /* unspecified */,
create_symlinks = /* unspecified */,
create_hard_links = /* unspecified */
};
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). none represents the empty bitmask; every other enumerator represents a distinct bitmask element.
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 Meaning
options controlling copy_file() when the file already exists
none Report an error (default behavior)
skip_existing Keep the existing file, without reporting an error.
overwrite_existing Replace the existing file
update_existing Replace the existing file only if it is older than the file being copied
options controlling the effects of copy() on subdirectories
none Skip subdirectories (default behavior)
recursive Recursively copy subdirectories and their content
options controlling the effects of copy() on symbolic links
none Follow symlinks (default behavior)
copy_symlinks Copy symlinks as symlinks, not as the files they point to
skip_symlinks Ignore symlinks
options controlling the kind of copying copy() does
none Copy file content (default behavior)
directories_only Copy the directory structure, but do not copy any non-directory files
create_symlinks 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 Instead of creating copies of files, create hardlinks that resolve to the same files as the originals
Example
// Run this code
#include <iostream>
#include <fstream>
#include <filesystem>
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)
// 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");
}
See also
copy copies files or directories
(function)
(C++17)
copy_file copies file contents
(function)
(C++17)
Pages related to std::filesystem::copy_options
- std::filesystem::copy_file (3) - std::filesystem::copy_file
- std::filesystem::copy_symlink (3) - std::filesystem::copy_symlink
- std::filesystem::copy (3) - std::filesystem::copy
- std::filesystem::canonical,std::filesystem::weakly_canonical (3) - std::filesystem::canonical,std::filesystem::weakly_canonical
- std::filesystem::create_directory,std::filesystem::create_directories (3) - std::filesystem::create_directory,std::filesystem::create_directories
- std::filesystem::create_hard_link (3) - std::filesystem::create_hard_link
- std::filesystem::create_symlink,std::filesystem::create_directory_symlink (3) - std::filesystem::create_symlink,std::filesystem::create_directory_symlink
- std::filesystem::current_path (3) - std::filesystem::current_path
- std::filesystem::absolute (3) - std::filesystem::absolute
- std::filesystem::begin(directory_iterator),std::filesystem::end(directory_iterator) (3) - std::filesystem::begin(directory_iterator),std::filesystem::end(directory_iterator)
- std::filesystem::begin(recursive_directory_iterator), (3) - std::filesystem::begin(recursive_directory_iterator),
- std::filesystem::begin(recursive_directory_iterator),std::filesystem::end(recursive_directory_iterator) (3) - std::filesystem::begin(recursive_directory_iterator),std::filesystem::end(recursive_directory_iterator)
- std::filesystem::directory_entry (3) - std::filesystem::directory_entry
- std::filesystem::directory_entry::assign (3) - std::filesystem::directory_entry::assign
- std::filesystem::directory_entry::directory_entry (3) - std::filesystem::directory_entry::directory_entry
- std::filesystem::directory_entry::exists (3) - std::filesystem::directory_entry::exists
- std::filesystem::directory_entry::file_size (3) - std::filesystem::directory_entry::file_size
- std::filesystem::directory_entry::hard_link_count (3) - std::filesystem::directory_entry::hard_link_count
- std::filesystem::directory_entry::is_block_file (3) - std::filesystem::directory_entry::is_block_file
- std::filesystem::directory_entry::is_character_file (3) - std::filesystem::directory_entry::is_character_file
- std::filesystem::directory_entry::is_directory (3) - std::filesystem::directory_entry::is_directory