From e12d5e0aaf09b9ba9514119c124bd00d50277eef Mon Sep 17 00:00:00 2001 From: leejet Date: Sat, 11 Oct 2025 00:18:39 +0800 Subject: [PATCH] fix: ensure directory iteration results are sorted by filename (#858) --- examples/cli/main.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/examples/cli/main.cpp b/examples/cli/main.cpp index b720671..b231638 100644 --- a/examples/cli/main.cpp +++ b/examples/cli/main.cpp @@ -1103,10 +1103,19 @@ bool load_images_from_dir(const std::string dir, return false; } + std::vector 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);