fix: ensure directory iteration results are sorted by filename (#858)

This commit is contained in:
leejet 2025-10-11 00:18:39 +08:00 committed by GitHub
parent 940a2018e1
commit e12d5e0aaf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1103,10 +1103,19 @@ bool load_images_from_dir(const std::string dir,
return false;
}
std::vector<fs::directory_entry> entries;
for (const auto& entry : fs::directory_iterator(dir)) {
if (!entry.is_regular_file())
continue;
if (entry.is_regular_file()) {
entries.push_back(entry);
}
}
std::sort(entries.begin(), entries.end(),
[](const fs::directory_entry& a, const fs::directory_entry& b) {
return a.path().filename().string() < b.path().filename().string();
});
for (const auto& entry : entries) {
std::string path = entry.path().string();
std::string ext = entry.path().extension().string();
std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);