本文介绍标头的 C++17 std::filesystem 实现 <filesystem> 中的枚举。
注释
此页面记录 C++17 std::filesystem 枚举。 有关 MSVC 提供 <experimental/filesystem>的历史标准枚举,请参阅 <experimental/filesystem> 枚举。
要求
标头:<filesystem>
命名 空间:std::filesystem
copy_options
用于 copy 指定行为的位掩码值的枚举和 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
};
值
| “属性” | 描述 |
|---|---|
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 |
特殊字符文件。 (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
};