From ed41782e1929e06f15ac84bdcd0cce1c75e5dba5 Mon Sep 17 00:00:00 2001 From: sjtubinlong Date: Mon, 16 Dec 2019 13:04:18 +0800 Subject: [PATCH] Update C++ infer: search images on windows os --- deploy/cpp/utils/utils.h | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/deploy/cpp/utils/utils.h b/deploy/cpp/utils/utils.h index 45ffde50..4578a6a8 100644 --- a/deploy/cpp/utils/utils.h +++ b/deploy/cpp/utils/utils.h @@ -23,7 +23,8 @@ #include #ifdef _WIN32 -#include +#define GLOG_NO_ABBREVIATED_SEVERITIES +#include #else #include #include @@ -67,15 +68,21 @@ namespace utils { // scan a directory and get all files with input extensions inline std::vector get_directory_images( const std::string& path, const std::string& exts) { + std::string pattern(path); + pattern.append("\\*"); std::vector imgs; - for (const auto& item : - std::experimental::filesystem::directory_iterator(path)) { - auto suffix = item.path().extension().string(); - if (exts.find(suffix) != std::string::npos && suffix.size() > 0) { - auto fullname = path_join(path, - item.path().filename().string()); - imgs.push_back(item.path().string()); - } + WIN32_FIND_DATA data; + HANDLE hFind; + if ((hFind = FindFirstFile(pattern.c_str(), &data)) != INVALID_HANDLE_VALUE) { + do { + auto fname = std::string(data.cFileName); + auto pos = fname.rfind("."); + auto ext = fname.substr(pos + 1); + if (ext.size() > 1 && exts.find(ext) != std::string::npos) { + imgs.push_back(path + "\\" + data.cFileName); + } + } while (FindNextFile(hFind, &data) != 0); + FindClose(hFind); } return imgs; } -- GitLab