std::experimental::filesystem::copy_options
來自 cppreference.com
< cpp | experimental | fs
定義於標頭檔案 <experimental/filesystem> |
||
enum class copy_options { none = 0, |
(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"); }
[編輯] 參閱
複製檔案或目錄 (函式) | |
複製檔案內容 (函式) |