c++: list files in folder

This commit is contained in:
Alexander Popov 2024-04-11 00:25:14 +03:00
parent 4b17968cc9
commit 4f4ec2bc91

View File

@ -0,0 +1,17 @@
#include <iostream>
#include <set>
#include <filesystem>
int main(int argc, char const *argv[]) {
std::set<std::filesystem::path> sorted_by_name;
for (const auto &entry : std::filesystem::directory_iterator("/home/user")) {
sorted_by_name.insert(entry.path());
}
for (auto &filename : sorted_by_name) {
std::cout << filename.c_str() << std::endl;
}
return 0;
}