Manuscript Documentation
v2026.12.0

@std/os/path.ms#

Import each required symbol with import Name from "@std/os/path.ms".

Glob Native type#

A compiled glob pattern that can be reused across paths. It matches *, ?, [...] classes, {a,b} and {1..3} braces, @(..), +(..), ?(..), !(..) and *(..) groups, and ** segments, as matches_glob does.

Manuscript
type Glob {
}

Glob.matches#

Tests one lexical path against the compiled pattern; a path with a NUL byte returns EINVAL.

Manuscript
fn matches(path String) Result[Bool, Error]

PathOperations Interface#

Path operations using either POSIX or Windows path conventions.

Manuscript
interface PathOperations {
    fn basename(path String) String
    fn basename_without(path String, suffix String) String
    fn dirname(path String) String
    fn extension(path String) String
    fn is_absolute(path String) Bool
    fn join(parts List[String]) String
    fn normalize(path String) String
    fn relative(base String, target String) Result[String, Error]
    fn resolve(base String, parts List[String]) Result[String, Error]
    fn parse(path String) PathParts
    fn format(parts PathParts) String
    fn separator() String
    fn delimiter() String
    fn to_namespaced_path(path String) String
    fn matches_glob(path String, pattern String) Result[Bool, Error]
    fn compile_glob(pattern String) Result[Glob, Error]
    fn stem(path String) String
    fn with_extension(path String, extension String) String
}

PathOperations.basename#

Returns the last component after ignoring trailing separators under this view’s path rules.

Manuscript
fn basename(path String) String

PathOperations.basename_without#

Returns the basename with suffix removed when it matches exactly. It is not an extension stripper: a suffix equal to the whole basename is not removed.

Manuscript
fn basename_without(path String, suffix String) String

PathOperations.compile_glob#

Compiles a glob pattern once for matching many paths under this dialect’s rules; malformed patterns return EINVAL.

Manuscript
fn compile_glob(pattern String) Result[Glob, Error]

PathOperations.delimiter#

Returns colon for POSIX or semicolon for Windows path-list entries.

Manuscript
fn delimiter() String

PathOperations.dirname#

Returns the directory component using the selected POSIX or Windows convention.

Manuscript
fn dirname(path String) String

PathOperations.extension#

Returns the final dot extension, or empty text for extensionless names and simple dotfiles.

Manuscript
fn extension(path String) String

PathOperations.format#

Builds a path from parts, preferring directory over root and base over name plus extension.

Manuscript
fn format(parts PathParts) String

PathOperations.is_absolute#

Tests absolute-root syntax; a Windows drive-relative spelling is not absolute.

Manuscript
fn is_absolute(path String) Bool

PathOperations.join#

Joins nonempty parts and normalizes separators/dot segments without filesystem access.

Manuscript
fn join(parts List[String]) String

PathOperations.matches_glob#

Tests one lexical path against the supported glob syntax; malformed patterns return EINVAL.

Manuscript
fn matches_glob(path String, pattern String) Result[Bool, Error]

PathOperations.normalize#

Cleans repeated separators and dot segments lexically; it does not resolve symlinks.

Manuscript
fn normalize(path String) String

PathOperations.parse#

Splits the original spelling into root, directory, base, extension and name without filesystem access.

Manuscript
fn parse(path String) PathParts

PathOperations.relative#

Computes the lexical relative path from base to target, both absolute. Paths with different roots, such as Windows drives, return target normalized. A relative argument or a NUL byte returns EINVAL.

Manuscript
fn relative(base String, target String) Result[String, Error]

PathOperations.resolve#

Resolves parts against the absolute base, without consulting the process working directory. A relative base or a NUL byte returns EINVAL.

Manuscript
fn resolve(base String, parts List[String]) Result[String, Error]

PathOperations.separator#

Returns slash for POSIX or backslash for Windows path components.

Manuscript
fn separator() String

PathOperations.stem#

Returns the final component without its extension under this dialect’s rules.

Manuscript
fn stem(path String) String

PathOperations.to_namespaced_path#

Returns a Windows namespaced absolute path when applicable; POSIX paths are unchanged.

Manuscript
fn to_namespaced_path(path String) String

PathOperations.with_extension#

Replaces the final extension, or adds one when absent, under this dialect’s rules.

Manuscript
fn with_extension(path String, extension String) String

PathParts Type#

The components of a path: root, directory, base, extension, and name. parse splits a path into them and format joins them again.

Manuscript
type PathParts {
    root String
    directory String
    base String
    extension String
    name String
}

PathParts.base#

Final component with its extension; format prefers it over name plus extension.

Manuscript
base String

PathParts.directory#

Directory portion, including the root when present; format prefers it over root.

Manuscript
directory String

PathParts.extension#

Final extension including its dot; simple dotfiles and dot/dot-dot components have no extension.

Manuscript
extension String

PathParts.name#

Final component with its extension removed, retaining the original spelling.

Manuscript
name String

PathParts.root#

Root prefix under the chosen path rules, including a POSIX slash or Windows drive/UNC root.

Manuscript
root String

basename Function#

Returns the final path component, excluding trailing separators.

Manuscript
fn basename(path String) String { ... }

basename_without Function#

Returns the basename with suffix removed when it matches exactly. A suffix equal to the whole basename is not removed.

Manuscript
fn basename_without(path String, suffix String) String { ... }

compile_glob Function#

Compiles a glob pattern under the host path rules. Malformed patterns return EINVAL.

Manuscript
fn compile_glob(pattern String) Result[Glob, Error] { ... }

delimiter Function#

Returns the host’s path-list delimiter.

Manuscript
fn delimiter() String { ... }

dirname Function#

Returns the directory portion of a path, or . when it has none.

Manuscript
fn dirname(path String) String { ... }

extension Function#

Returns the final extension, including its leading dot, or an empty string.

Manuscript
fn extension(path String) String { ... }

format Function#

Formats parsed path components as a path string.

Manuscript
fn format(parts PathParts) String { ... }

is_absolute Function#

Reports whether a path is absolute according to the host path rules.

Manuscript
fn is_absolute(path String) Bool { ... }

join Function#

Joins path parts using the host separator and normalizes the result.

Manuscript
fn join(parts List[String]) String { ... }

matches_glob Function#

Tests a path against a glob pattern. To test many paths against one pattern, compile it once with compile_glob.

Manuscript
fn matches_glob(path String, pattern String) Result[Bool, Error] { ... }

normalize Function#

Normalizes separators and dot segments without accessing the filesystem.

Manuscript
fn normalize(path String) String { ... }

parse Function#

Splits a path into its root, directory, base, extension, and name.

Manuscript
fn parse(path String) PathParts { ... }

posix Function#

Returns path operations using POSIX separators and parsing rules.

Manuscript
fn posix() PathOperations { ... }

relative Function#

Computes a relative path from base to target using host path rules.

Manuscript
fn relative(base String, target String) Result[String, Error] { ... }

resolve Function#

Resolves path parts against a base using host path conventions.

Manuscript
fn resolve(base String, parts List[String]) Result[String, Error] { ... }

separator Function#

Returns the host’s path separator.

Manuscript
fn separator() String { ... }

stem Function#

Returns the final component without its extension: stem("a/b.tar.gz") is "b.tar" and a dotfile such as .bashrc keeps its whole name.

Manuscript
fn stem(path String) String { ... }

to_namespaced_path Function#

On Windows, returns the \\?\ namespaced form of an absolute path; elsewhere, and for other paths, returns the path unchanged.

Manuscript
fn to_namespaced_path(path String) String { ... }

windows Function#

Returns path operations using Windows separators and parsing rules.

Manuscript
fn windows() PathOperations { ... }

with_extension Function#

Replaces the final extension, or adds one when there is null, keeping the directory: with_extension("a/b.txt", "md") is "a/b.md". A leading dot in extension is optional and an empty extension removes the current one. A path with no final component, such as "/", comes back unchanged.

Manuscript
fn with_extension(path String, extension String) String { ... }