add utils::path_dirname() to complement utils::path_basename()

This commit is contained in:
Axel Kohlmeyer
2020-10-23 20:12:03 -04:00
parent c51d2a286a
commit b931501711
3 changed files with 38 additions and 0 deletions

View File

@ -772,6 +772,22 @@ std::string utils::path_basename(const std::string &path) {
return path.substr(start);
}
/* ----------------------------------------------------------------------
Return only the leading part of a path, return just the directory
------------------------------------------------------------------------- */
std::string utils::path_dirname(const std::string &path) {
#if defined(_WIN32)
size_t start = path.find_last_of("/\\");
#else
size_t start = path.find_last_of("/");
#endif
if (start == std::string::npos) return ".";
return path.substr(0,start);
}
/* ----------------------------------------------------------------------
join two paths
------------------------------------------------------------------------- */