Standard library
Path
Path join, clean, relative paths, and shallow walk.
Introduction
Path join, clean, relative paths, and shallow walk. Import std/path to bind the module as path. Call free functions as path.name(...). Struct methods use a receiver value.
/ std/path
This page is the package reference for std/path. Private helpers used only by co-located tests are not listed.
Functions
Free functions on path. Each function has a short description, an example, then parameters and return shape.
join
Joins base and rel using platform path rules. Call form: path.join(base, rel).
/ std/path
$ p = path.join("/tmp", "a.txt")Parameters: base: base path. rel: relative segment or path. Returns: Joined path string.
is_abs
Reports whether path p is absolute. Call form: path.is_abs(p).
/ std/path
$ ok = path.is_abs("/tmp/a")Parameters: p: path string. Returns: Boolean true for absolute paths.
file_name
Returns the final component of path p. Call form: path.file_name(p).
/ std/path
$ name = path.file_name("/tmp/a.txt")Parameters: p: path string. Returns: Final path component as a string.
parent
Returns the parent directory of path p. Call form: path.parent(p).
/ std/path
$ dir = path.parent("/tmp/a/b")Parameters: p: path string. Returns: Parent path string.
extension
Returns the file extension of path p when present. Call form: path.extension(p).
/ std/path
$ ext = path.extension("/tmp/a.txt")Parameters: p: path string. Returns: Extension string, or empty when none.
clean
Cleans . and .. segments in a path (POSIX-ish). Call form: path.clean(p).
/ std/path
$ p = path.clean("/tmp/./a/../b")Parameters: p: path string. Returns: Cleaned path string.
rel
Builds a relative path from base to target. Call form: path.rel(base, target).
/ std/path
| path.rel("/tmp", "/tmp/a/b") {
$ r { }
! e { }
}Parameters: base: base path. target: target path. Returns: Result. Ok arm: relative path string. Err arm: "rel failed".
walk
Lists paths for direct children of root (non-recursive). Call form: path.walk(root).
/ std/path
$ kids = path.walk(p'.')
Parameters: root: directory path as string or locator. Returns: List of child path strings.