From 0e23357a529270c631f2d10545bf6cd267044547 Mon Sep 17 00:00:00 2001 From: huangyongan Date: Mon, 24 Apr 2023 20:38:10 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=95=B0=E5=AD=97=E6=AF=94=E8=BE=83?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=AF=94=E8=BE=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/main.cpp b/main.cpp index 9d354f6..fd7b3bd 100644 --- a/main.cpp +++ b/main.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #define K_VISION_DIR "/hard/k_vision" #define AI_VISION_DIR "/hard/ai_vision" @@ -92,7 +93,7 @@ std::vector get_search_paths(const std::string& strFileName, int nB return vs; } -std::vector cvt_filename_to_datetime(const std::string& strFileName, int nBeginTime, int nEndTime) +std::vector get_file_timestamp_range(const std::string& strFileName, int nBeginTime, int nEndTime) { std::vector vs; if (strFileName.empty() || nBeginTime > nEndTime) @@ -115,18 +116,18 @@ std::vector cvt_filename_to_datetime(const std::string& strFileName tt[2] = tt[0] + nEndTime; tm* tm_begin = localtime(&tt[1]); char szBegin[255]; - snprintf(szBegin, sizeof(szBegin),"%d%02d%02d_%02d%02d%02d", + snprintf(szBegin, sizeof(szBegin),"%d%02d%02d%02d%02d%02d", tm_begin->tm_year + 1900, tm_begin->tm_mon + 1, tm_begin->tm_mday, tm_begin->tm_hour, tm_begin->tm_min, tm_begin->tm_sec); tm* tm_end = localtime(&tt[2]); char szEnd[255]; - snprintf(szEnd, sizeof(szEnd),"%d%02d%02d_%02d%02d%02d", + snprintf(szEnd, sizeof(szEnd),"%d%02d%02d%02d%02d%02d", tm_end->tm_year + 1900, tm_end->tm_mon + 1, tm_end->tm_mday, tm_end->tm_hour, tm_end->tm_min, tm_end->tm_sec); - vs.push_back(szBegin); - vs.push_back(szEnd); + vs.push_back(std::atoll(szBegin)); + vs.push_back(std::atoll(szEnd)); return vs; } -std::string get_file_timestamp_str(const std::string& strPath) +long long get_file_timestamp(const std::string& strPath) { std::string str; if (strPath.empty()) @@ -135,7 +136,8 @@ std::string get_file_timestamp_str(const std::string& strPath) } str = path.filename().string(); auto strTime = str.substr(0, 15); - return strTime; + std::remove(strTime.begin(), strTime.end(), '_'); + return std::atoll(strTime.c_str()); } int main(int argc, char* argv[]) { @@ -171,7 +173,7 @@ int main(int argc, char* argv[]) { for (auto it:vec_file_name) { ++j; - auto vec_datetime = cvt_filename_to_datetime(it, nParam[0], nParam[1]); + auto vec_datetime = get_file_timestamp_range(it, nParam[0], nParam[1]); if (vec_datetime.empty()) { continue; @@ -182,8 +184,8 @@ int main(int argc, char* argv[]) { auto vec_file_path = get_file_paths(dir); for (auto path:vec_file_path) { - auto strTime = get_file_timestamp_str(path); - if (strTime >= vec_datetime.front() && strTime <= vec_datetime.back()) + auto timestamp = get_file_timestamp(path); + if (timestamp >= vec_datetime.front() && timestamp <= vec_datetime.back()) { vec_matched_path.push_back(path); }