<experimental/filesystem> 列舉

Important

<experimental/filesystem>標頭與std::experimental::filesystem命名空間提供了檔案系統技術規範(TS)的預先實作。 此文件保留用於針對 MSVC 原始檔案系統實作撰寫的程式碼,該實作自 MSVC 版本 14.51 起被移除。 新程式碼則改用 C++17 <filesystem> 標頭和 std::filesystem 命名空間。 關於這些列舉的標準等價物,請參見<filesystem>列舉。

本文記錄了歷史前標準 std::experimental::filesystem 實作中的列舉情況。

Requirements

標頭:<experimental/filesystem>

命名空間:std::experimental::filesystem

copy_options

一種 位元 遮罩值的枚舉,用於複製與 copy_file 函式來指定行為。

語法

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
};

價值

Name Description
none 執行該操作的預設行為。
skip_existing 如果檔案已經存在,請勿複製,也不要回報錯誤。
overwrite_existing 如果檔案已經存在,就覆寫它。
update_existing 如果檔案已經存在且比替換檔案還舊,則會覆寫該檔案。
recursive 遞迴複製子目錄及其內容。
copy_symlinks 將符號連結複製為符號連結,而不是複製它們指向的檔案。
skip_symlinks 忽略象徵性連結。
directories_only 只遍歷目錄,忽略檔案。
create_symlinks 建立符號連結,而不是複製檔案。 除非目的地是目前的目錄,否則必須使用絕對路徑作為來源路徑。
create_hard_links 用硬連結代替複製檔案。

directory_options

一種位元遮罩枚舉,用來控制目錄迭代如何處理指向目錄的符號連結。

語法

enum class directory_options {
   none = 0,
   follow_directory_symlink = 1
};

價值

Name Description
none 預設行為:不要跟隨指向目錄的符號連結。
follow_directory_symlink 請跟隨象徵性的目錄連結,而非跳過。

file_type

檔案類型的列舉。

語法

enum class file_type {
   not_found = -1,
   none = 0,
    regular,
    directory,
    symlink,
    block,
    character,
    fifo,
    socket,
    unknown
};

這些列舉器的底層整數值並非固定,因此不應依賴特定的數值。

價值

Name Description
none 檔案類型尚未被評估,或是在評估時發生錯誤。
not_found 檔案沒找到。
regular 一個普通的檔案。
directory 目錄。
symlink 象徵性的連結。
block 一個區塊特殊檔案。 (未用於 Windows。)
character 一個 character-special 檔案。 (未用於 Windows。)
fifo FIFO 或管道檔案。 (未用於 Windows。)
socket 一個插座。 (未用於 Windows。)
unknown 檔案存在,但無法確定其類型。

永久

一個位元遮罩的檔案權限位元枚舉,以及該函式用來決定如何套用這些位元的控制旗標 permissions 。 在 Windows 上,支援的權限值基本上是「唯讀」和 all。 唯讀檔案則沒有設定任何 *_write 位元。 否則, all 位元(0777)為設定。

語法

enum class perms {// names for permissions
   none = 0,
   owner_read = 0400,  // S_IRUSR
   owner_write = 0200, // S_IWUSR
   owner_exec = 0100,  // S_IXUSR
   owner_all = 0700,   // S_IRWXU
   group_read = 040,   // S_IRGRP
   group_write = 020,  // S_IWGRP
   group_exec = 010,   // S_IXGRP
   group_all = 070,    // S_IRWXG
   others_read = 04,   // S_IROTH
   others_write = 02,  // S_IWOTH
   others_exec = 01,   // S_IXOTH
   others_all = 07,    // S_IRWXO
   all = 0777,
   set_uid = 04000,    // S_ISUID
   set_gid = 02000,    // S_ISGID
   sticky_bit = 01000, // S_ISVTX
   mask = 07777,
   unknown = 0xFFFF,
   add_perms = 0x10000,       // control flag
   remove_perms = 0x20000,    // control flag
   resolve_symlinks = 0x40000 // control flag
};

控制旗標

與以獨立perm_options枚舉控制permissions函式的 C++17 std::filesystem 實作不同,前標準的 TS 實作本身攜帶控制旗標perms。

Name Description
add_perms 將指定的權限位元加入檔案目前的權限,而不是替換它們。
remove_perms 從檔案目前的權限中移除指定的權限位元。
resolve_symlinks 解析符號連結,使權限變更適用於目標檔案而非連結。

參見

<experimental/filesystem>
<experimental/filesystem> 函數
<experimental/filesystem> 操作員