std::filesystem::directory_entry::exists

bool exists() const;
bool exists( std::error_code& ec ) const noexcept;
(C++17 起)

检查所指的对象是否存在。各自等效于返回 std::filesystem::exists(status())std::filesystem::exists(status(ec))

目录

参数

ec - 不抛出重载中报告错误的输出参数

返回值

若被指代文件系统对象存在则为 true

异常

不接受 std::error_code& 参数的重载在底层 OS API 错误时抛出 filesystem_error ,以第一参数 p 和作为错误码参数的 OS 错误码构造。若内存分配失败则可能抛出 std::bad_alloc 。若 OS API 调用失败,则接受 std::error_code& 参数的重载设置该参数为 OS API 错误码,而若不出现错误则执行 ec.clear()

示例

参阅

(C++17)
检查路径是否表示既存的文件系统对象
(函数)

版本历史

  • (当前 | 先前) 2017年4月30日 (日) 21:32Fruderica讨论 | 贡献. . (713字节) (+713). . (以“{{cpp/filesystem/directory_entry/title|exists}} {{cpp/filesystem/directory_entry/navbar}} {{dcl begin}} {{dcl | since=c++17 | 1= bool exists() const; bool exists( st...”为内容创建页面)