std::filesystem::directory_entry::exists
Min standard notice:
Checks whether the pointed-to object exists. Effectively returns:
# Declarations
bool exists() const;
(since C++17)
bool exists( std::error_code& ec ) const noexcept;
(since C++17)
# Parameters
ec: out-parameter for error reporting in the non-throwing overload
# Return value
true if the referred-to filesystem object exists.
# Example
#include <filesystem>
#include <iostream>
int main()
{
for (auto const str:
{
"/usr/bin/cat",
"/usr/bin/mouse",
"/usr/bin/python",
"/usr/bin/bison",
"/usr/bin/yacc",
"/usr/bin/c++",
})
{
std::filesystem::directory_entry entry{str};
std::cout << "directory entry " << entry
<< (entry.exists() ? " exists\n" : " does not exist\n");
}
}