mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-07 05:00:54 +08:00
Added utility functions to support (get file from path and get directory from path)
This commit is contained in:
@@ -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.
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user