Statting files with directory_entry
Note
Beware! directory_entry
is the most bleeding-edge part of the C++17 <filesystem>
library. What I am about to describe is neither implemented by Boost, nor by <experimental/filesystem>
.
Retrieving a file's metadata from its inode is done by querying an object of type fs::directory_entry
. If you're familiar with the POSIX approach to retrieving metadata, imagine that a fs::directory_entry
contains a member of type fs::path
and a member of type std::optional<struct stat>
. Calling entry.refresh()
is, basically, the same thing as calling the POSIX function stat()
; and calling any accessor
method, such as entry.file_size()
, will implicitly call stat()
if and only if the optional member is still disengaged. Merely constructing an instance of fs::directory_entry
won't query the filesystem; the library waits until you ask a specific question before it acts. Asking a specific question, such as entry.file_size()
, may cause the library to query...