Skip to content

Path Module

The std/path module provides cross-platform utilities for working with file and directory paths.

import { path } from "std/path";

Joins path segments with the OS path separator and cleans the result.

println(path.join("/usr", "local", "bin")); // "/usr/local/bin"
println(path.join("src", "utils", "index.chuks")); // "src/utils/index.chuks"

Returns the absolute path.

const full = path.abs("./src/main.chuks");
println(full); // e.g. "/home/user/project/src/main.chuks"

Cleans a path by resolving . and .. segments.

println(path.clean("/usr/local/../bin/./chuks")); // "/usr/bin/chuks"

path.rel(base: string, target: string): string

Section titled “path.rel(base: string, target: string): string”

Returns the relative path from base to target.

println(path.rel("/usr/local", "/usr/local/bin/chuks")); // "bin/chuks"

Returns the last element of the path (the file name).

println(path.base("/usr/local/bin/chuks")); // "chuks"
println(path.base("/path/to/file.txt")); // "file.txt"

Returns the directory portion of the path.

println(path.dir("/usr/local/bin/chuks")); // "/usr/local/bin"

Returns the file extension including the dot.

println(path.ext("app.chuks")); // ".chuks"
println(path.ext("archive.tar.gz")); // ".gz"

Returns the file name without the extension.

println(path.stem("/path/to/file.txt")); // "file"
println(path.stem("app.chuks")); // "app"

Returns true if the path is absolute.

println(path.isAbs("/usr/local")); // true
println(path.isAbs("relative/path")); // false

path.match(pattern: string, name: string): bool

Section titled “path.match(pattern: string, name: string): bool”

Returns true if the name matches the glob pattern.

println(path.match("*.chuks", "main.chuks")); // true
println(path.match("*.go", "main.chuks")); // false

Returns the OS path separator (/ on Unix, \ on Windows).

println(path.separator()); // "/" on macOS/Linux
import { path } from "std/path";
// Build paths safely
const projectDir = path.join(path.cwd(), "src");
const mainFile = path.join(projectDir, "main.chuks");
println("Project: " + projectDir);
println("Main file: " + mainFile);
println("Extension: " + path.ext(mainFile));
println("Stem: " + path.stem(mainFile));
println("Is absolute: " + string(path.isAbs(mainFile)));
// Resolve relative paths
const from = "/Users/dev/project";
const to = "/Users/dev/project/src/lib/utils.chuks";
println("Relative: " + path.rel(from, to)); // "src/lib/utils.chuks"