Path#
File path retrieval and manipulation functions.
Info
To use declarations from this page, include the <essence/path.hpp> header.
-
std::optional<std::string> path::which(const std::string &name)#
Search the
PATHenvironment variable directories for executablename.Parameter
namemay also be a const char*.Example
auto result_a = path::which("gcc"); auto result_b = path::which("some-non-existent-executable"); // *result_a holds: "/usr/bin/gcc" // result_b holds: std::nullopt
-
std::string path::base(const std::string &name)#
Return the basename of
name.Parameter
namemay also be a const char*.Example
std::string compiler { "/usr/bin/gcc" }; auto result = path::base(compiler); // result holds: "gcc"
-
std::string path::dir(const std::string &name)#
Return the directory name of
name.Parameter
namemay also be a const char*.Example
std::string compiler { "/usr/bin/gcc" }; auto result = path::dir(compiler); // result holds: "/usr/bin"
-
std::string path::home()#
Return the users’ home directory path.
-
std::string &path::expandhome(std::string &path)#
Expand tilde (
~) to the users’ home directory (in-place).Example
// In this example, the invoking user is 'wbr' std::string screenshots_dir { "~/pictures/screenshots" }; path::expandhome(screenshots_dir); // screenshots_dir now holds: "/home/wbr/pictures/screenshots"
-
std::string path::cexpandhome(std::string_view path)#
Expand tilde (
~) to the users’ home directory (copying).