From 322176cc69f55532fd7464fd896b3e421bf684e4 Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Sat, 17 Oct 2015 08:52:16 -0400 Subject: [PATCH] Added utility functions to support (get file from path and get directory from path) --- src/openalpr/support/filesystem.cpp | 27 +++++++++++++++++++++++++++ src/openalpr/support/filesystem.h | 3 +++ 2 files changed, 30 insertions(+) diff --git a/src/openalpr/support/filesystem.cpp b/src/openalpr/support/filesystem.cpp index e8df8ac..a970788 100644 --- a/src/openalpr/support/filesystem.cpp +++ b/src/openalpr/support/filesystem.cpp @@ -114,7 +114,34 @@ namespace alpr int lastindex = filename.find_last_of("."); return filename.substr(0, lastindex); } + + std::string get_filename_from_path(std::string file_path) + { + size_t found; + found=file_path.find_last_of("/\\"); + + if (found >= 0) + return file_path.substr(found+1); + + return ""; + + } + + std::string get_directory_from_path(std::string file_path) + { + if (DirectoryExists(file_path.c_str())) + return file_path; + + size_t found; + + found=file_path.find_last_of("/\\"); + + if (found >= 0) + return file_path.substr(0,found); + + return ""; + } #ifdef WINDOWS // Stub out these functions on Windows. They're used for the daemon anyway, which isn't supported on Windows. diff --git a/src/openalpr/support/filesystem.h b/src/openalpr/support/filesystem.h index b73d539..09b2e54 100644 --- a/src/openalpr/support/filesystem.h +++ b/src/openalpr/support/filesystem.h @@ -41,6 +41,9 @@ namespace alpr bool stringCompare( const std::string &left, const std::string &right ); bool makePath(const char* path, mode_t mode); + + std::string get_directory_from_path(std::string file_path); + std::string get_filename_from_path(std::string file_path); } #endif // FILESYSTEM_H