Skip to content

Commit e12d5e0

Browse files
authored
fix: ensure directory iteration results are sorted by filename (#858)
1 parent 940a201 commit e12d5e0

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

examples/cli/main.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,10 +1103,19 @@ bool load_images_from_dir(const std::string dir,
11031103
return false;
11041104
}
11051105

1106+
std::vector<fs::directory_entry> entries;
11061107
for (const auto& entry : fs::directory_iterator(dir)) {
1107-
if (!entry.is_regular_file())
1108-
continue;
1108+
if (entry.is_regular_file()) {
1109+
entries.push_back(entry);
1110+
}
1111+
}
1112+
1113+
std::sort(entries.begin(), entries.end(),
1114+
[](const fs::directory_entry& a, const fs::directory_entry& b) {
1115+
return a.path().filename().string() < b.path().filename().string();
1116+
});
11091117

1118+
for (const auto& entry : entries) {
11101119
std::string path = entry.path().string();
11111120
std::string ext = entry.path().extension().string();
11121121
std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);

0 commit comments

Comments
 (0)