<filesystem> 列舉

本文記錄了標頭 C++17 std::filesystem 實作 <filesystem> 中的列舉。

Note

本頁記錄了 C++17 std::filesystem 的列舉。 關於 MSVC 在 <experimental/filesystem>中提供的歷史前標準列舉,請參見<experimental/filesystem>列舉。

需求

標頭:<filesystem>

命名空間:std::filesystem

copy_options

一個位元遮罩值的枚舉,你用copycopy_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
};

值

名稱 描述
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,
   skip_permission_denied = 2
};

值

名稱 描述
none 預設行為:不要跟隨指向目錄的符號連結,並將權限被拒絕視為錯誤。
follow_directory_symlink 請跟隨象徵性的目錄連結,而非跳過。
skip_permission_denied 默默跳過那些本來會導致權限拒絕錯誤的目錄。

file_type

檔案類型的列舉。

語法

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

C++ 標準並未固定這些列舉器的底層整數值,因此不要依賴特定的數值。

值

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

perm_options

一個位元遮罩枚舉,控制函式如何 permissions 套用權限位元。

語法

enum class perm_options {
   replace = 1,
   add = 2,
   remove = 4,
   nofollow = 8
};

值

名稱 描述
replace 將檔案的權限位元替換為指定的權限。
add 將指定的權限位元加入檔案目前的權限。
remove 從檔案目前的權限中移除指定的權限位元。
nofollow 更改符號連結本身的權限,而非它解析到的檔案。

perms

一個檔案權限位元的位元遮罩枚舉。 在 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
};

另請參閱

標頭檔參考
<filesystem>