std::filesystem::directory_entry::status,std::filesystem::directory_entry::symlink_status (3) - Linux Manuals
std::filesystem::directory_entry::status,std::filesystem::directory_entry::symlink_status: std::filesystem::directory_entry::status,std::filesystem::directory_entry::symlink_status
NAME
std::filesystem::directory_entry::status,std::filesystem::directory_entry::symlink_status - std::filesystem::directory_entry::status,std::filesystem::directory_entry::symlink_status
Synopsis
std::filesystem::file_status status() const; (1) (since C++17)
std::filesystem::file_status status( std::error_code& ec ) const noexcept;
std::filesystem::file_status symlink_status() const; (2) (since C++17)
std::filesystem::file_status symlink_status( std::error_code& ec ) const noexcept;
1) Returns status of the entry, as if determined by a status call (symlinks are followed to their targets)
2) Returns status of the entry, as if determined by a symlink_status call (symlinks are not followed)
Parameters
ec - out-parameter for error reporting in the non-throwing overload
Return value
The status of the file referred to by the entry.
Exceptions
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 path argument and the OS error code as the error code argument. 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. Any overload not marked noexcept may throw std::bad_alloc if memory allocation fails.
Notes
Many low-level OS APIs for directory traversal retrieve file attributes along with the next directory entry. The constructors and the non-const member functions of directory_iterator store these attributes, if any, in the pointed-to directory_entry without calling directory_entry::refresh, which makes it possible to examine the attributes of the directory entries as they are being iterated over, without making additional system calls.
Example
// Run this code
Possible output:
See also
refresh (public member function)
exists (public member function)
is_block_file (public member function)