std.path

std.path resolves, joins, and decomposes filesystem paths.

Reference

home()            # user home directory
expand(path)      # expand ~ and $NAME / ${NAME} (%NAME% on Windows)
join(part, ...)   # join parts; later parts treated as segments
normalize(part, ...)  # join + collapse '.', '..', duplicate separators
resolve(part, ...)    # join + normalize + expand; requires the path to exist
exists(path)
filename(path)  stem(path)  extension(path)  parent(path)
cwd()

join treats parts after the first as segments — a leading / on them does
not jump to the filesystem root. join is purely structural: it dedups
separators and drops . segments, but keeps .. verbatim (resolving ..
needs filesystem knowledge, e.g. symlinks). Use normalize to collapse ..
lexically. resolve throws FILE_NOT_FOUND unless the resolved path exists.

Examples

var cfg = std.path.join(std.path.home(), ".config", "scrii")
print(cfg)                       # /home/you/.config/scrii

var clean = std.path.normalize("/a/./b/../c")     # /a/c
print(clean)

var kept = std.path.join("a", "..", "b")           # a/../b (.. is NOT collapsed)
print(kept)

var f = std.path.filename("/x/report.txt")        # report.txt
print(std.path.stem(f))          # report
print(std.path.extension(f))     # .txt (leading dot included; "" when none)
print(std.path.parent("/x/report.txt"))           # /x

Edge cases follow `std::filesystem`: `extension("noext")` and
`extension("/x/.hidden")` are both `""` (leading-dot files have no
extension), `stem("/x/archive.tar.gz")` is `"archive.tar"` (last extension
only), and `parent("/")` is `"/"`.

print(std.path.exists("/tmp"))   # true
print(std.path.expand("~/docs")) # /home/you/docs
print(std.path.cwd())            # current directory

expand handles ~, $VAR, ${VAR}, and %VAR% (Windows), matching the
automatic expansion performed by std.file operations.

See also

  • std.file — file I/O that consumes these paths
  • std.env — environment variables expanded by expand
  • std.os — std.chdir and process helpers