@std/path.ms#
Import each required symbol with import Name from "@std/path.ms".
PathError Alternative#
Errors returned when a path cannot be parsed or resolved.
type PathError:
case InvalidInputimpl Error for PathError:
fn message() -> String:PathError.InvalidInput#
Invalid NUL input, a nonabsolute resolve/relative anchor or malformed glob syntax.
case InvalidInputPathError.Error.message#
Returns a path-prefixed diagnostic without revealing the supplied paths or pattern.
fn message() -> String: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, PathError]
fn resolve(base: String, parts: List[String]) -> Result[String, PathError]
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, PathError]PathOperations.basename#
Returns the last component after ignoring trailing separators under this view’s path rules.
fn basename(path: String) -> StringPathOperations.basename_without#
Removes an exact suffix under basename compatibility rules; it does not strip arbitrary extensions.
fn basename_without(path: String, suffix: String) -> StringPathOperations.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 with directory preferred over root, and base preferred 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 InvalidInput.
fn matches_glob(path: String, pattern: String) -> Result[Bool, PathError]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 a lexical relative path from absolute anchors; different roots return the original target. Nonabsolute anchors or invalid NUL input return InvalidInput.
fn relative(base: String, target: String) -> Result[String, PathError]PathOperations.resolve#
Resolves parts against an explicit absolute base; no process working directory is consulted.
fn resolve(base: String, parts: List[String]) -> Result[String, PathError]PathOperations.separator#
Returns slash for POSIX or backslash for Windows path components.
fn separator() -> StringPathOperations.to_namespaced_path#
Returns a Windows namespaced absolute path when applicable; POSIX paths are unchanged.
fn to_namespaced_path(path: String) -> StringPathParts Record#
Parsed path components using the familiar root, directory, base, extension, and name fields.
type PathParts:
root: String
directory: String
base: String
extension: String
name: StringPathParts.base#
Final component with extension; it takes precedence over name/extension during format.
base: StringPathParts.directory#
Directory portion, including the root when present; it takes precedence over root during format.
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 the supplied suffix removed when it matches.
fn basename_without(path: String, suffix: String) -> String:delimiter Function#
Returns the host’s path-list delimiter.
fn delimiter() -> String:dirname Function#
Returns the directory portion of a path.
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.
fn matches_glob(path: String, pattern: String) -> Result[Bool, PathError]: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, PathError]:resolve Function#
Resolves path parts against a base using host path conventions.
fn resolve(base: String, parts: List[String]) -> Result[String, PathError]:separator Function#
Returns the host’s path separator.
fn separator() -> String:to_namespaced_path Function#
Converts a path to the host’s namespaced representation when applicable.
fn to_namespaced_path(path: String) -> String:win32 Function#
Returns path operations using Windows separators and parsing rules.
fn win32() -> PathOperations: