描述通过取消引用或recursive_directory_iterator取消引用directory_iterator所返回的对象。 包装 directory_entry 一个 path ,作为优化,可以缓存在循环访问目录时获取的文件属性。
语法
class directory_entry;
备注
对象directory_entry存储 .path 作为优化,它还可以缓存路径引用的文件的属性和状态。 当条目由目录迭代器创建或调用 refresh时,将填充缓存的数据。 观察程序(例如file_size,statuslast_write_time和各种谓词)is_*在可用时返回缓存的数据;否则,它们查询文件系统。
有关详细信息和代码示例,请参阅文件系统导航 (C++)。
构造函数
| 构造函数 | 说明 |
|---|---|
directory_entry |
构造一个 directory_entry。 |
成员函数
| 成员函数 | 说明 |
|---|---|
assign |
替换存储的路径并刷新缓存的属性。 |
exists |
检查条目是否引用现有文件。 |
file_size |
获取所引用文件的大小(以字节为单位)。 |
hard_link_count |
获取指向所引用文件的硬链接数。 |
is_block_file |
检查引用的文件是否为块特殊文件。 |
is_character_file |
检查引用的文件是否为字符特殊文件。 |
is_directory |
检查引用的文件是否为目录。 |
is_fifo |
检查引用的文件是否为命名管道(FIFO)。 |
is_other |
检查引用的文件是否为其他文件。 |
is_regular_file |
检查引用的文件是否为常规文件。 |
is_socket |
检查引用的文件是否为套接字。 |
is_symlink |
检查引用的文件是否为符号链接。 |
last_write_time |
获取所引用文件上次数据修改的时间。 |
path |
返回存储的路径。 |
refresh |
刷新缓存的文件属性。 |
replace_filename |
替换存储路径的文件名并刷新缓存的属性。 |
status |
获取引用的文件的状态,并遵循符号链接。 |
symlink_status |
获取引用文件的状态,而不使用以下符号链接。 |
运算符
| 运算符 | 说明 |
|---|---|
operator= |
分配给 .directory_entry |
operator const path& |
返回存储的路径。 |
operator== |
检查两个 directory_entry 对象是否相等。 |
operator<=> |
对两 directory_entry 个对象执行三向比较。 (C++20) |
operator!= |
检查两个 directory_entry 对象是否不相等。 C++17 中的显式成员;通过 C++20 及更高版本中重写的比较支持。 |
operator< |
检查排序是否 directory_entry 在另一个 directory_entry排序之前。 C++17 中的显式成员;通过 C++20 及更高版本中重写的比较支持。 |
operator<= |
directory_entry检查排序之前还是等于另一种directory_entry排序。 C++17 中的显式成员;通过 C++20 及更高版本中重写的比较支持。 |
operator> |
检查排序是否 directory_entry 在另一个 directory_entry之后排序。 C++17 中的显式成员;通过 C++20 及更高版本中重写的比较支持。 |
operator>= |
directory_entry检查排序后还是等于另一个directory_entry排序。 C++17 中的显式成员;通过 C++20 及更高版本中重写的比较支持。 |
要求
标头:<filesystem>
命名 空间:std::filesystem
directory_entry
构造一个 directory_entry。
directory_entry() noexcept = default;
directory_entry(const directory_entry&) = default;
directory_entry(directory_entry&&) noexcept = default;
explicit directory_entry(const std::filesystem::path& p);
directory_entry(const std::filesystem::path& p, std::error_code& ec);
~directory_entry();
参数
p
条目引用的文件的路径。
ec
操作的输出错误代码。
备注
默认、复制和移动构造函数的行为与预期相同。 采用 path 存储 p 然后调用 refresh 以填充缓存属性的构造函数。 在 error_codeec 中报告错误而不是引发的重载,并在刷新失败时清除存储的路径。
operator=
分配给 .directory_entry
directory_entry& operator=(const directory_entry&) = default;
directory_entry& operator=(directory_entry&&) noexcept = default;
参数
right
要 directory_entry 复制或移动到此 directory_entry中。
备注
默认赋值运算符的行为与预期相同。
分配
替换存储的路径并刷新缓存的属性。
void assign(const std::filesystem::path& p);
void assign(const std::filesystem::path& p, std::error_code& ec);
参数
p
存储的新路径。
ec
操作的输出错误代码。
备注
将存储的路径替换为 p,然后调用 refresh 以更新缓存的属性。 在 error_codeec 中报告错误的重载,而不是引发。
replace_filename
替换存储路径的文件名并刷新缓存的属性。
void replace_filename(const std::filesystem::path& p);
void replace_filename(const std::filesystem::path& p, std::error_code& ec);
参数
p
替换文件名。
ec
操作的输出错误代码。
备注
将存储路径的文件名组件替换为 p,如下所示 path().replace_filename(p),然后调用 refresh。 在 error_codeec 中报告错误的重载,而不是引发。
刷新
刷新缓存的文件属性。
void refresh();
void refresh(std::error_code& ec) noexcept;
参数
ec
操作的输出错误代码。
备注
读取存储路径引用的文件的属性,并将其缓存在 .directory_entry 调用 refresh 在引用的文件更改后更新缓存的数据。 在 error_codeec 中报告错误的重载,而不是引发。
路径
返回存储的路径。
const std::filesystem::path& path() const noexcept;
运算符 const path&
返回存储的路径。
operator const std::filesystem::path&() const noexcept;
存在
检查条目是否引用现有文件。
bool exists() const;
bool exists(std::error_code& ec) const noexcept;
参数
ec
操作的输出错误代码。
返回值
true 如果存储的路径引用现有文件,则为 ;否则,为 false. 等效于调用 filesystem::exists(status())。
is_block_file
检查引用的文件是否为块特殊文件。
bool is_block_file() const;
bool is_block_file(std::error_code& ec) const noexcept;
参数
ec
操作的输出错误代码。
返回值
true 如果引用的文件是块特殊文件,则为否则,为 false. 此函数始终在falseWindows返回。
is_character_file
检查引用的文件是否为字符特殊文件。
bool is_character_file() const;
bool is_character_file(std::error_code& ec) const noexcept;
参数
ec
操作的输出错误代码。
返回值
true 如果引用的文件是字符特殊文件,则为 ;否则,为 false. 此函数始终在falseWindows返回。
is_directory
检查引用的文件是否为目录。
bool is_directory() const;
bool is_directory(std::error_code& ec) const noexcept;
参数
ec
操作的输出错误代码。
返回值
true 如果引用的文件是目录,则为否则,为 false. 等效于调用 filesystem::is_directory(status())。
is_fifo
检查引用的文件是否为命名管道(FIFO)。
bool is_fifo() const;
bool is_fifo(std::error_code& ec) const noexcept;
参数
ec
操作的输出错误代码。
返回值
true 如果引用的文件是 FIFO,则为否则,为 false. 此函数始终在falseWindows返回。
is_other
检查引用的文件是否为其他文件。
bool is_other() const;
bool is_other(std::error_code& ec) const noexcept;
参数
ec
操作的输出错误代码。
返回值
true 如果引用的文件存在,但不是常规文件、目录或符号链接,则为 ;否则,为 false. 等效于调用 filesystem::is_other(status())。
is_regular_file
检查引用的文件是否为常规文件。
bool is_regular_file() const;
bool is_regular_file(std::error_code& ec) const noexcept;
参数
ec
操作的输出错误代码。
返回值
true 如果引用的文件是常规文件,则为否则,为 false. 等效于调用 filesystem::is_regular_file(status())。
is_socket
检查引用的文件是否为套接字。
bool is_socket() const;
bool is_socket(std::error_code& ec) const noexcept;
参数
ec
操作的输出错误代码。
返回值
true 如果引用的文件是套接字,则为否则,为 false. 此函数始终在falseWindows返回。
is_symlink
检查引用的文件是否为符号链接。
bool is_symlink() const;
bool is_symlink(std::error_code& ec) const noexcept;
参数
ec
操作的输出错误代码。
返回值
true 如果引用的文件是符号链接,则为否则,为 false. 等效于调用 filesystem::is_symlink(symlink_status())。
文件大小
获取所引用文件的大小(以字节为单位)。
uintmax_t file_size() const;
uintmax_t file_size(std::error_code& ec) const noexcept;
参数
ec
操作的输出错误代码。
返回值
所引用文件的大小(以字节为单位),就像按 .filesystem::file_size(path()) 可用时使用缓存数据。
hard_link_count
获取指向所引用文件的硬链接数。
uintmax_t hard_link_count() const;
uintmax_t hard_link_count(std::error_code& ec) const noexcept;
参数
ec
操作的输出错误代码。
返回值
指向所引用文件的硬链接数,就好像通过 。filesystem::hard_link_count(path()) 可用时使用缓存数据。
last_write_time
获取所引用文件上次数据修改的时间。
file_time_type last_write_time() const;
file_time_type last_write_time(std::error_code& ec) const noexcept;
参数
ec
操作的输出错误代码。
返回值
所引用文件上次数据修改的时间,就好像按该时间。filesystem::last_write_time(path()) 可用时使用缓存数据。
状态
获取引用的文件的状态,并遵循符号链接。
file_status status() const;
file_status status(std::error_code& ec) const noexcept;
参数
ec
操作的输出错误代码。
返回值
所引用文件的状态,就像按 filesystem::status(path()). 可用时使用缓存数据。
symlink_status
获取引用文件的状态,而不使用以下符号链接。
file_status symlink_status() const;
file_status symlink_status(std::error_code& ec) const noexcept;
参数
ec
操作的输出错误代码。
返回值
所引用文件的符号链接状态,就像按 filesystem::symlink_status(path()). 可用时使用缓存数据。
operator==
检查两个 directory_entry 对象是否相等。
bool operator==(const directory_entry& right) const noexcept;
参数
right
要 directory_entry 与之进行比较。
返回值
返回 path() == right.path()。
operator<=>
对两 directory_entry 个对象执行三向比较。
std::strong_ordering operator<=>(const directory_entry& right) const noexcept; // C++20
参数
right
要 directory_entry 与之进行比较。
返回值
返回 path() <=> right.path()。
备注
在 C++20 及更高版本中可用。 编译器重写使用operator<、operator<=operator>或operator>=使用此运算符的比较。 它重写了用于 operator!= 使用的 operator==比较。
operator!=
检查两个 directory_entry 对象是否不相等。
bool operator!=(const directory_entry& right) const noexcept; // C++17
参数
right
要 directory_entry 与之进行比较。
返回值
返回 !(*this == right)。
备注
在 C++17 中,此运算符是显式声明的成员函数。 在 C++20 及更高版本中,将使用 operator!= 的表达式重写为使用 operator==。
operator<
检查排序是否 directory_entry 在另一个 directory_entry排序之前。
bool operator<(const directory_entry& right) const noexcept; // C++17
参数
right
要 directory_entry 与之进行比较。
返回值
返回 path() < right.path()。
备注
在 C++17 中,此运算符是显式声明的成员函数。 在 C++20 及更高版本中,将使用 operator< 的表达式重写为使用 operator<=>。
operator<=
directory_entry检查排序之前还是等于另一种directory_entry排序。
bool operator<=(const directory_entry& right) const noexcept; // C++17
参数
right
要 directory_entry 与之进行比较。
返回值
返回 !(right < *this)。
备注
在 C++17 中,此运算符是显式声明的成员函数。 在 C++20 及更高版本中,将使用 operator<= 的表达式重写为使用 operator<=>。
operator>
检查排序是否 directory_entry 在另一个 directory_entry之后排序。
bool operator>(const directory_entry& right) const noexcept; // C++17
参数
right
要 directory_entry 与之进行比较。
返回值
返回 right < *this。
备注
在 C++17 中,此运算符是显式声明的成员函数。 在 C++20 及更高版本中,将使用 operator> 的表达式重写为使用 operator<=>。
operator>=
directory_entry检查排序后还是等于另一个directory_entry排序。
bool operator>=(const directory_entry& right) const noexcept; // C++17
参数
right
要 directory_entry 与之进行比较。
返回值
返回 !(*this < right)。
备注
在 C++17 中,此运算符是显式声明的成员函数。 在 C++20 及更高版本中,将使用 operator>= 的表达式重写为使用 operator<=>。