std::filesystem::exists

From cppreference.com
 
 
 
Defined in header <filesystem>
(1) (since C++17)
bool exists( const std::filesystem::path& p );
bool exists( const std::filesystem::path& p, std::error_code& ec )
(2) (since C++17)

Checks if the given file status or path corresponds to an existing file or directory.

1) Equivalent to status_known(s) && s.type() != file_type::not_found.
2) Equivalent to exists(status(p)) or exists(status(p, ec)) (symlinks are followed). The non-throwing overload returns false if an error occurs.

Parameters

s - file status to check
p - path to examine
ec - out-parameter for error reporting in the non-throwing overload

Return value

true if the given path or file status corresponds to an existing file or directory, false otherwise.

Exceptions

1)
noexcept specification:  
noexcept
  
2) The overload that does not take a std::error_code& parameter throws filesystem_error on underlying OS API errors, constructed with p as the first argument and the OS error code as the error code argument. std::bad_alloc may be thrown if memory allocation fails. The overload taking a std::error_code& parameter sets it to the OS API error code if an OS API call fails, and executes ec.clear() if no errors occur. This overload has
noexcept specification:  
noexcept
  

Notes

The information provided by this function is usually also provided as a byproduct of directory iteration. During directory iteration, calling exists(*iterator) is less efficient than exists(iterator->status())