From 383090c89c6314cf95df08f70be451d8353a7e2a Mon Sep 17 00:00:00 2001 From: LZY Date: Mon, 24 Apr 2023 15:11:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E7=94=A8boost=E7=9A=84filesystem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 4 +++- main.cpp | 30 ++++++++++++++---------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a88d6ea..1f189ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,8 @@ -cmake_minimum_required(VERSION 3.25) +cmake_minimum_required(VERSION 3.5) project(ajx_find_files) set(CMAKE_CXX_STANDARD 17) add_executable(ajx_find_files main.cpp) + +target_link_libraries(ajx_find_files boost_system boost_filesystem) diff --git a/main.cpp b/main.cpp index 419184b..8648ed3 100644 --- a/main.cpp +++ b/main.cpp @@ -1,24 +1,25 @@ #include -#include +#include #include #include #define K_VISION_DIR "/hard/k_vision" #define AI_VISION_DIR "/hard/ai_vision" +namespace fs = boost::filesystem; std::vector get_file_names(const std::string& strDir) { std::vector vs; - std::filesystem::path path(strDir); - if (!std::filesystem::exists(path)) + fs::path path(strDir); + if (!fs::exists(path)) { return vs; } - std::filesystem::directory_iterator dir_iter(path); + fs::directory_iterator dir_iter(path); for (auto it:dir_iter) { - if (it.is_regular_file() && it.exists()) + if (fs::is_regular_file(it) && fs::exists(it)) { vs.push_back(it.path().filename().string()); } @@ -29,15 +30,15 @@ std::vector get_file_names(const std::string& strDir) std::vector get_file_paths(const std::string& strDir) { std::vector vs; - std::filesystem::path path(strDir); - if (!std::filesystem::exists(path)) + fs::path path(strDir); + if (!fs::exists(path)) { return vs; } - std::filesystem::directory_iterator dir_iter(path); + fs::directory_iterator dir_iter(path); for (auto it:dir_iter) { - if (it.is_regular_file() && it.exists()) + if (fs::is_regular_file(it) && fs::exists(it)) { vs.push_back(it.path().string()); } @@ -129,7 +130,7 @@ int main(int argc, char* argv[]) { char szSaveDir[255]; snprintf(szSaveDir, sizeof (szSaveDir), "%s/%d%02d%02d/", AI_VISION_DIR, tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday); - std::filesystem::create_directories(szSaveDir); + fs::create_directories(szSaveDir); auto vec_file_name = get_file_names(K_VISION_DIR); if (vec_file_name.empty()) { @@ -162,14 +163,11 @@ int main(int argc, char* argv[]) { int i = 0; for (auto it:vec_matched_path) { - std::filesystem::path path(it); + fs::path path(it); auto strName = path.filename().string(); std::string strPath = std::string(szSaveDir) + "/" + strName; - bool bRet = std::filesystem::copy_file(it,strName,std::filesystem::copy_options::overwrite_existing); - if (bRet) - { - ++i; - } + fs::copy_file(it,strName,fs::copy_option::overwrite_if_exists); + ++i; if (i % 50 == 0) { std::cout << "info: copy progress " << i << "/" << vec_matched_path.size() << std::endl;