Path¶
Operations on paths that do not require a capability. The operations can be used to manipulate path names, but give no access to the resulting paths.
All paths use / as the separator on every platform, including Windows.
Paths obtained through Path.cwd() and Path.canonical() are already
/-separated. clean() normalizes any remaining \ on Windows.
is_sep() still accepts \ on Windows for parsing external input.
Use to_os() when a backslash path is needed for Windows shell commands.
Constructors¶
create¶
Returns¶
- Path val^
Public Functions¶
is_sep¶
Determine if a byte is a path separator.
Parameters¶
- c: U8 val
Returns¶
- Bool val
sep¶
Return the path separator as a string.
Returns¶
- String val
is_abs¶
Return true if the path is an absolute path.
Parameters¶
- path: String val
Returns¶
- Bool val
join¶
Join two paths together. If the next_path is absolute, simply return it. The returned path will be cleaned.
Parameters¶
Returns¶
- String val
clean¶
Replace multiple separators with a single /.
On Windows, normalize \ to /.
Remove instances of . from the path.
Remove instances of .. and the preceding path element from the path.
A leading // (exactly two separators) is preserved as a network path
prefix per POSIX; three or more leading separators collapse to one.
The result will have no trailing slash unless it is a root directory.
If the result would be empty, "." will be returned instead.
Parameters¶
- path: String val
Returns¶
- String val
normcase¶
Lowercases the path on case-insensitive platforms (Windows, macOS). Returns the path unchanged on case-sensitive platforms.
Parameters¶
- path: String val
Returns¶
- String val
cwd¶
Returns the program's working directory. Setting the working directory is not supported, as it is not concurrency-safe.
Returns¶
- String val
abs¶
Returns a cleaned, absolute path.
Parameters¶
- path: String val
Returns¶
- String val
rel¶
Returns a path such that Path.join(to, Path.rel(to, target)) == target. Raises an error if this isn't possible.
Parameters¶
Returns¶
- String val ?
split¶
Splits the path into a pair, (head, tail) where tail is the last pathname component and head is everything leading up to that. The tail part will never contain a slash; if path ends in a slash, tail will be empty. If there is no slash in path, head will be empty. If path is empty, both head and tail are empty. The path in head will be cleaned before it is returned. In all cases, join(head, tail) returns a path to the same location as path (but the strings may differ). Also see the functions dir() and base().
Parameters¶
Returns¶
base¶
Return the path after the last separator, or the whole path if there is no
separator.
If with_ext is false, the extension as defined by the ext() method
will be omitted from the result.
Parameters¶
Returns¶
- String val
dir¶
Return a cleaned path before the last separator, or the whole path if there is no separator.
Parameters¶
- path: String val
Returns¶
- String val
ext¶
Return the file extension, i.e. the part after the last dot as long as that dot is after all separators. Return an empty string for no extension.
Parameters¶
- path: String val
Returns¶
- String val
volume¶
Return the volume at the beginning of the path, if there is one.
On Windows, this includes drive letters (C:), extended-length prefixes
(\\?\), and UNC bases (\\server\share).
On all platforms, a path beginning with exactly two separators followed by
a non-separator is treated as a network path (//host/share), matching the
POSIX rule that a pathname beginning with exactly two slashes is
implementation-defined. Three or more leading slashes are not a network
path and collapse to one in clean().
Parameters¶
- path: String val
Returns¶
- String val
to_os¶
Convert forward slashes to the OS native separator. On Windows this
replaces / with \; on all other platforms it returns path unchanged.
Use when passing a path to cmd.exe or another Windows tool that
interprets / as an option flag.
Parameters¶
- path: String val
Returns¶
- String val
canonical¶
Return the equivalent canonical absolute path. Raise an error if there isn't one.
Parameters¶
- path: String val
Returns¶
- String val ?
is_list_sep¶
Determine if a byte is a path list separator.
Parameters¶
- c: U8 val
Returns¶
- Bool val
list_sep¶
Return the path list separator as a string.
Returns¶
- String val
split_list¶
Separate a list of paths into an array of cleaned paths.
Parameters¶
- path: String val
Returns¶
random¶
Returns a pseudo-random base, suitable as a temporary file name or directory name, but not guaranteed to not already exist.
Parameters¶
- len: USize val = 6
Returns¶
- String val
eq¶
Parameters¶
- that: Path val
Returns¶
- Bool val
ne¶
Parameters¶
- that: Path val
Returns¶
- Bool val