Path#
File path retrieval and manipulation functions.
Info
To use declarations from this page, include the <essence/path.hpp> header.
-
std::string temp()#
Get the path to the systems’ canonical temporary directory.
Reads the environment for the value of
TMPDIRif set, otherwise falling back to/tmpif it exists. If neither work, an exception is thrown.
-
std::optional<std::string> path::which(std::string_view name)#
Search the
PATHenvironment variable directories for executablename.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(std::string_view name)#
Return the basename of
name.Example
std::string compiler { "/usr/bin/gcc" }; auto result = path::base(compiler); // result holds: "gcc"
-
std::string path::dir(std::string_view name)#
Return the directory name of
name.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).