path
local path = require("@std/path")WARNING
These APIs are still open to future evolution. In new major versions, they may change in backwards incompatible ways.
Summary
| Entry | Description |
|---|---|
| Path | A structured, platform-aware file system path. |
| Pathlike | Anything that can be used as a path: a string, a Path, or raw path data. |
| basename | Returns the last component of path (the filename or directory name), or nil if the path has no components. |
| dirname | Returns the directory portion of path as a string (everything except the last component). |
| extname | Returns the file extension of path (including the leading dot), or "" if there is none. |
| format | Converts path to its string representation using the platform's separator. |
| isAbsolute | Returns true if path is absolute. |
| join | Joins one or more path segments together into a single Path. Each segment after the first must be relative. |
| normalize | Returns a normalized form of path, resolving . and .. components and removing redundant separators. |
| parse | Parses path into a structured Path value. |
| relative | Returns the relative path from from to to. Both paths must be of the same kind (both absolute or both relative). |
| resolve | Resolves a sequence of paths into an absolute Path, processing right-to-left and falling back to the current working directory. |
Types
Path
A structured, platform-aware file system path.
type Path = pathtypes.PathPathlike
Anything that can be used as a path: a string, a Path, or raw path data.
type Pathlike = pathtypes.PathlikeFunctions and Properties
path.basename
Returns the last component of path (the filename or directory name), or nil if the path has no components.
(path: Pathlike) -> string?path.dirname
Returns the directory portion of path as a string (everything except the last component).
(path: Pathlike) -> stringpath.extname
Returns the file extension of path (including the leading dot), or "" if there is none.
(path: Pathlike) -> stringpath.format
Converts path to its string representation using the platform's separator.
(path: Pathlike) -> stringpath.isAbsolute
Returns true if path is absolute.
(path: Pathlike) -> booleanpath.join
Joins one or more path segments together into a single Path. Each segment after the first must be relative.
(...: Pathlike) -> Pathpath.normalize
Returns a normalized form of path, resolving . and .. components and removing redundant separators.
(path: Pathlike) -> Pathpath.parse
Parses path into a structured Path value.
(path: Pathlike) -> Pathpath.relative
Returns the relative path from from to to. Both paths must be of the same kind (both absolute or both relative).
(from: Pathlike, to: Pathlike) -> Pathpath.resolve
Resolves a sequence of paths into an absolute Path, processing right-to-left and falling back to the current working directory.
(...: Pathlike) -> Path