首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::filesystem::copy_options

Defined in header <filesystem>

?

?

enum class 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)

此类型表示控制copy()copy_file()功能。

copy_options满足…的要求BitmaskType%28,这意味着按位运算符operator&,,,operator|,,,operator^,,,operator~,,,operator&=,,,operator|=,和operator^=为此类型%29定义。

成员常数

以下选项组中最多可能存在一个复制选项,否则复制函数的行为是未定义的。

Member constant

Meaning

选项控制拷贝[医]当文件已经存在时,文件%28%29

没有报告错误%28默认行为%29

跳过[医]现有保存现有文件,而不报告错误。

覆写[医]现有替换现有文件

更新[医]仅当现有文件比要复制的文件旧时才替换现有文件

控制复制%28%29对子目录的影响的选项

None Skip子目录%28默认行为%29

递归复制子目录及其内容

控制复制%28%29对符号链接的影响的选项

没有一个遵循符号链接%28默认行为%29

复制[医]符号链接将符号链接复制为符号链接,而不是它们指向的文件。

跳过[医]符号链接忽略符号链接

控制复制类型%28%29的选项

不复制文件内容%28默认行为%29

目录[医]只复制目录结构,但不复制任何非目录文件。

创造[医]符号链接,而不是创建文件副本,创建指向原始文件的符号链接。注意:除非目标路径位于当前目录中,否则源路径必须是绝对路径。

创造[医]硬[医]链接,而不是创建文件的副本,创建硬链接解析到相同的文件作为原件。

二次

代码语言:javascript
复制
#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");
}

二次

另见

copy (C++17)

copies files or directories (function)

copy_file (C++17)

copies file contents (function)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com