according to
https://en.cppreference.com/w/cpp/experimental/fs/directory_iterator

The iteration order is unspecified, except that

How to go through the directory and sort the contents?

std::string html; for (auto & p : std::experimental::filesystem::directory_iterator(filepath)) { std::string current = format("<p><a href=""%s"">%s</a></p>", p.path().filename().c_str(), p.path().filename().c_str()); html += current; } 

It is desirable that this was such an order: first, all the folders in alphabetical order, then the files in alphabetical order.

The only solution at the moment is to first put folders into a vector of folders, files into files vector in the first pass through the directory, then sort vector1, vector2 and collect back into the resultant vector, but somehow cumbersome ...

  • Well, since this is an input iterator , there is no other way ... - Harry
  • Not the only one. It can be added not into a vector, but into std :: set, then it will immediately be sorted. :] - bipll 1:51 pm
  • one
    std::set contains unique objects. And files in different folders can have the same name. Thus, some of the files may disappear. - Alexander Petrov
  • one
    As an option, during the passage: if the item is a folder, add the vector to the desired point ( example ), if the item is a file, write it to the additional vector. After the passage, we sort the vector of 'files' into the resultant vector like that - acade

0