Answer the question
In order to leave comments, you need to log in
STL. filesystem. Is there a way to reverse iterate over a directory?
Please do not confuse with recursive iteration. I need to somehow get fs::directory_entry
from the end to the beginning. There are no methods operator--()
or decrement()
the class fs::directory_iterator
, there are no traits for the constructor either. The type class is fs::reverse_directory_iterator
missing. So is there a way?
Answer the question
In order to leave comments, you need to log in
In general, the most normal way is to create std::set<fs::path>
and fill it with content, and then use a reverse iterator std::set
.
std::set<fs::path> file_paths;
for (const auto& dir_entry : fs::directory_iterator{"path/to/directory"})
file_paths.insert(dir_entry.path());
auto iter = file_paths.rbegin();
auto end = file_paths.rend();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question