名稱空間
變體
操作

std::experimental::filesystem::copy_options

來自 cppreference.com
< cpp‎ | experimental‎ | fs
 
 
實驗性
技術規範
檔案系統庫 (檔案系統 TS)
庫基礎 (庫基礎 TS)
庫基礎 2 (庫基礎 TS v2)
庫基礎 3 (庫基礎 TS v3)
並行性擴充套件 (並行性 TS)
並行性擴充套件 2 (並行性 TS v2)
併發性擴充套件 (併發性 TS)
併發擴充套件 2 (concurrency TS v2)
概念 (概念 TS)
範圍 (範圍 TS)
反射 (反射 TS)
數學特殊函式 (特殊函式 TR)
實驗性非 TS
模式匹配
線性代數
std::execution
契約
2D 圖形
 
 
定義於標頭檔案 <experimental/filesystem>
enum class copy_options {

    none = 0,
    skip_existing = 1,
    overwrite_existing = 2,
    update_existing = 4,
    recursive = 8,
    copy_symlinks = 16,
    skip_symlinks = 32,
    directories_only = 64,
    create_symlinks = 128,
    create_hard_links = 256

};
(filesystem TS)

此型別表示可用的選項,它們控制 copy()copy_file() 函式的行為。

copy_options 滿足 位掩碼型別 (BitmaskType) 的要求(這意味著位運算子 operator&operator|operator^operator~operator&=operator|=operator^= 都為此型別定義)。

[編輯] 成員常量

以下每個選項組中最多隻能存在一個複製選項,否則複製函式的行為是未定義的。

成員常量 含義
當檔案已存在時控制 copy_file() 的選項
0 報告錯誤(預設行為)。
skip_existing 1 保留現有檔案,不報告錯誤。
overwrite_existing 2 替換現有檔案。
update_existing 4 僅當現有檔案比要複製的檔案舊時才替換它。
控制 copy() 對子目錄的影響的選項
0 跳過子目錄(預設行為)。
recursive 8 遞迴複製子目錄及其內容。
控制 copy() 對符號連結的影響的選項
0 跟隨符號連結(預設行為)。
copy_symlinks 16 將符號連結作為符號連結複製,而不是作為它們指向的檔案複製。
skip_symlinks 32 忽略符號連結。
控制 copy() 執行的複製型別選項
0 複製檔案內容(預設行為)。
directories_only 64 複製目錄結構,但不復制任何非目錄檔案。
create_symlinks 128 不建立檔案的副本,而是建立指向原始檔案的符號連結。注意:除非目標路徑在當前目錄中,否則源路徑必須是絕對路徑。
create_hard_links 256 不建立檔案的副本,而是建立解析為與原始檔案相同檔案的硬連結。

[編輯] 示例

#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");
}

[編輯] 參閱

複製檔案或目錄
(函式) [編輯]
複製檔案內容
(函式) [編輯]