path
Functions: Path.isSeparator, Path.splitDrive, Path.isAbsolute, Path.isRelative, Path.split, Path.dirname, Path.basename, Path.splitExtension, Path.extension, Path.stem, Path.stripExtension, Path.withExtension, Path.hasExtension, Path.isHidden, Path.join, Path.joinAll, Path.toPosixSeparators, Path.normalize, Path.relativePath, Path.components
Path.isSeparator
bool Path.isSeparator(char c)Returns true for '/' and ''.
Path.splitDrive
(string drive, string rest) Path.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.
Path.isAbsolute
bool Path.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.
Path.isRelative
bool Path.isRelative(string path)Returns true when the path is not absolute.
Path.split
(string dir, string base) Path.split(string path)Splits the path into (dir, base) at the last separator.
Mirrors Python's posixpath.split: Path.split("a/b") is ("a", "b"), Path.split("a/") is ("a", ""), Path.split("a") is ("", "a"), and Path.split("/a") is ("/", "a").
Path.dirname
string Path.dirname(string path)Returns the directory half of Path.split(path).
Path.basename
string Path.basename(string path)Returns the file half of Path.split(path).
Path.splitExtension
(string root, string ext) Path.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.
Path.extension
string Path.extension(string path)Returns the extension with its dot, or "" when there is none.
Path.stem
string Path.stem(string path)Returns the basename without its last extension.
Path.stripExtension
StringBuf Path.stripExtension(string path)Returns the path without its last extension.
Path.withExtension
StringBuf Path.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.
Path.hasExtension
bool Path.hasExtension(string path)Returns true when the path has an extension.
Path.isHidden
bool Path.isHidden(string path)Returns true when the basename starts with '.'. The special names "." and ".." don't count.
Path.join
StringBuf Path.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.
Path.joinAll
StringBuf Path.joinAll(string[] parts)Folds Path.join over the parts.
StringBuf Path.joinAll(List<string>& parts)Folds Path.join over a list; handy for rejoining Path.components() output.
Path.toPosixSeparators
StringBuf Path.toPosixSeparators(string path)Replaces '' with '/'.
Path.normalize
StringBuf Path.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 ".".
Path.relativePath
StringBuf Path.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.
Path.components
List<string> Path.components(string path)Splits the path into its non-empty parts.
"." and ".." are kept verbatim; a drive prefix, if present, is the first element.