Skip to main content

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. 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 f = std.path.filename("/x/report.txt") // report.txt
print(std.path.stem(f)) // report
print(std.path.extension(f)) // .txt
print(std.path.parent("/x/report.txt")) // /x

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

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.osstd.cwd / std.chdir vs std.path.cwd