@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.
type Glob {
}Glob.matches#
Tests one lexical path against the compiled pattern; a path with a NUL byte returns EINVAL.
fn matches(path String) Result[Bool, Error]PathOperations Interface#
Path operations using either POSIX or Windows path conventions.
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.
fn basename(path String) StringPathOperations.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.
fn basename_without(path String, suffix String) StringPathOperations.compile_glob#
Compiles a glob pattern once for matching many paths under this dialect’s rules; malformed patterns return EINVAL.
fn compile_glob(pattern String) Result[Glob, Error]PathOperations.delimiter#
Returns colon for POSIX or semicolon for Windows path-list entries.
fn delimiter() StringPathOperations.dirname#
Returns the directory component using the selected POSIX or Windows convention.
fn dirname(path String) StringPathOperations.extension#
Returns the final dot extension, or empty text for extensionless names and simple dotfiles.
fn extension(path String) StringPathOperations.format#
Builds a path from parts, preferring directory over root and base over
name plus extension.
fn format(parts PathParts) StringPathOperations.is_absolute#
Tests absolute-root syntax; a Windows drive-relative spelling is not absolute.
fn is_absolute(path String) BoolPathOperations.join#
Joins nonempty parts and normalizes separators/dot segments without filesystem access.
fn join(parts List[String]) StringPathOperations.matches_glob#
Tests one lexical path against the supported glob syntax; malformed patterns return EINVAL.
fn matches_glob(path String, pattern String) Result[Bool, Error]PathOperations.normalize#
Cleans repeated separators and dot segments lexically; it does not resolve symlinks.
fn normalize(path String) StringPathOperations.parse#
Splits the original spelling into root, directory, base, extension and name without filesystem access.
fn parse(path String) PathPartsPathOperations.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.
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.
fn resolve(base String, parts List[String]) Result[String, Error]PathOperations.separator#
Returns slash for POSIX or backslash for Windows path components.
fn separator() StringPathOperations.stem#
Returns the final component without its extension under this dialect’s rules.
fn stem(path String) StringPathOperations.to_namespaced_path#
Returns a Windows namespaced absolute path when applicable; POSIX paths are unchanged.
fn to_namespaced_path(path String) StringPathOperations.with_extension#
Replaces the final extension, or adds one when absent, under this dialect’s rules.
fn with_extension(path String, extension String) StringPathParts Type#
The components of a path: root, directory, base, extension, and name. parse splits
a path into them and format joins them again.
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.
base StringPathParts.directory#
Directory portion, including the root when present; format prefers it over
root.
directory StringPathParts.extension#
Final extension including its dot; simple dotfiles and dot/dot-dot components have no extension.
extension StringPathParts.name#
Final component with its extension removed, retaining the original spelling.
name StringPathParts.root#
Root prefix under the chosen path rules, including a POSIX slash or Windows drive/UNC root.
root Stringbasename Function#
Returns the final path component, excluding trailing separators.
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.
fn basename_without(path String, suffix String) String { ... }compile_glob Function#
Compiles a glob pattern under the host path rules. Malformed patterns return EINVAL.
fn compile_glob(pattern String) Result[Glob, Error] { ... }delimiter Function#
Returns the host’s path-list delimiter.
fn delimiter() String { ... }dirname Function#
Returns the directory portion of a path, or . when it has none.
fn dirname(path String) String { ... }extension Function#
Returns the final extension, including its leading dot, or an empty string.
fn extension(path String) String { ... }format Function#
Formats parsed path components as a path string.
fn format(parts PathParts) String { ... }is_absolute Function#
Reports whether a path is absolute according to the host path rules.
fn is_absolute(path String) Bool { ... }join Function#
Joins path parts using the host separator and normalizes the result.
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.
fn matches_glob(path String, pattern String) Result[Bool, Error] { ... }normalize Function#
Normalizes separators and dot segments without accessing the filesystem.
fn normalize(path String) String { ... }parse Function#
Splits a path into its root, directory, base, extension, and name.
fn parse(path String) PathParts { ... }posix Function#
Returns path operations using POSIX separators and parsing rules.
fn posix() PathOperations { ... }relative Function#
Computes a relative path from base to target using host path rules.
fn relative(base String, target String) Result[String, Error] { ... }resolve Function#
Resolves path parts against a base using host path conventions.
fn resolve(base String, parts List[String]) Result[String, Error] { ... }separator Function#
Returns the host’s path separator.
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.
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.
fn to_namespaced_path(path String) String { ... }windows Function#
Returns path operations using Windows separators and parsing rules.
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.
fn with_extension(path String, extension String) String { ... }