Skip to content

Path

1 min read

Import: import system.io;

Read the usage guide for examples and common tasks. This reference lists the public declarations for this part of the library. See Reading API signatures for parameter and result notation.

Path

Path helpers for joining and inspecting filesystem paths.

public static class Path

join

Joins path segments with the platform separator, skipping empty segments and avoiding duplicate separators. Supply additional segments as trailing arguments.

public static fun join(a: string, b: string, ...more: string[]): string

file_name

Final path component after the last / or \, or None for a trailing separator.

public static fun file_name(path: string): Option<string>

extension

Substring after the last . in the file name, or None when missing.

public static fun extension(path: string): Option<string>

parent

Directory portion of path, or None when there is no separator.

public static fun parent(path: string): Option<string>

is_absolute

True for POSIX absolute paths (/…), Windows drive paths (C:…), or \-rooted paths.

public static fun is_absolute(path: string): bool

normalize

Resolves . and .. segments where possible. Does not consult the filesystem.

public static fun normalize(path: string): string

separator

Host path separator. Always / in the WASM stdlib surface (native hosts accept / even on Windows); use OsFamily at call sites when Windows-style paths are required.

public static get separator(): string

stem

File name without the last extension ("a.tar.gz" → "a.tar").

public static fun stem(path: string): string

with_extension

Replaces the last extension, or appends ext when the path has none. ext may include a leading ..

public static fun with_extension(path: string, ext: string): string

with_file_name

Replaces the final path component with name.

public static fun with_file_name(path: string, name: string): string

has_extension

True when the last extension equals ext (with or without a leading .).

public static fun has_extension(path: string, ext: string): bool

components

Splits path on / and \, skipping empty segments.

public static fun components(path: string): string[]

absolute

Joins path onto the process cwd when it is relative, then normalizes. Does not consult realpath.

public static fun absolute(path: string): string

relative_to

String-prefix relative path after normalize (not realpath). None when path is not under base.

public static fun relative_to(path: string, base: string): Option<string>