path
Functions: isSeparator, splitDrive, isAbsolute, isRelative, split, dirname, basename, splitExtension, extension, stem, stripExtension, withExtension, hasExtension, isHidden, join, joinAll, toPosixSeparators, normalize, relativePath, components
isSeparator
bool isSeparator(char c)Returns true for '/' and ''.
splitDrive
(string drive, string rest) splitDrive(string path)Splits the drive/UNC prefix off the path.
The drive is "C:" for drive-letter paths, "//server/share" for UNC paths, or "" when there is no prefix.
isAbsolute
bool isAbsolute(string path)Returns true for rooted paths: "/a", "C:/a", "C:", and UNC roots. "C:a" is relative, as is anything else without a root.
isRelative
bool isRelative(string path)Returns true when the path is not absolute.
split
(string dir, string base) split(string path)Splits the path into (dir, base) at the last separator.
Mirrors Python's posixpath.split: split("a/b") is ("a", "b"), split("a/") is ("a", ""), split("a") is ("", "a"), and split("/a") is ("/", "a").
dirname
string dirname(string path)Returns the directory half of split(path).
basename
string basename(string path)Returns the file half of split(path).
splitExtension
(string root, string ext) splitExtension(string path)Splits off the last extension; the extension keeps its dot, or is "".
A dot counts only if it follows the last separator and a non-dot precedes it within the basename, so dotfiles have no extension.
extension
string extension(string path)Returns the extension with its dot, or "" when there is none.
stem
string stem(string path)Returns the basename without its last extension.
stripExtension
StringBuf stripExtension(string path)Returns the path without its last extension.
withExtension
StringBuf withExtension(string path, string newExt)Returns the path with its last extension replaced.
The new extension may be given with or without the dot, and "" strips the extension.
hasExtension
bool hasExtension(string path)Returns true when the path has an extension.
isHidden
bool isHidden(string path)Returns true when the basename starts with '.'. The special names "." and ".." don't count.
join
StringBuf join(string a, string b)Joins two segments with '/'.
A rooted b wins, keeping a's drive when b has none; a b with a different drive also wins. Empty a yields b, and empty b yields a with a trailing slash.
joinAll
StringBuf joinAll(string[] parts)Folds join over the parts.
StringBuf joinAll(List<string>& parts)Folds join over a list; handy for rejoining components() output.
toPosixSeparators
StringBuf toPosixSeparators(string path)Replaces '' with '/'.
normalize
StringBuf normalize(string path)Collapses duplicate separators, resolves "." and ".." lexically, converts '' to '/', and drops the trailing slash.
Going above the root stays at the root; leading ".." is preserved in relative paths. The drive prefix is preserved, and "" becomes ".".
relativePath
StringBuf relativePath(string from, string to)Returns the lexical relative path from from to
to.
When the drives differ or exactly one side is absolute, returns the
normalized to.
components
List<string> components(string path)Splits the path into its non-empty parts.
"." and ".." are kept verbatim; a drive prefix, if present, is the first element.