Added utility functions to support (get file from path and get directory from path)

This commit is contained in:
Matt Hill
2015-10-17 08:52:16 -04:00
parent ba69a50a8f
commit 322176cc69
2 changed files with 30 additions and 0 deletions

View File

@@ -115,6 +115,33 @@ namespace alpr
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.

View File

@@ -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