std/path
Functions
fn Clean(path: str): str
Returns the shortest path name equivalent to path by purely lexical processing. It applies the following rules iteratively until no further processing can be done:
- Replace multiple slashes with a single slash.
- Eliminate each . path name element (the current directory).
- Eliminate each inner .. path name element (the parent directory) along with the non-.. element that precedes it.
- Eliminate .. elements that begin a rooted path: that is, replace "/.." by "/" at the beginning of a path.
The returned path ends in a slash only if it is the root "/".
If the result of this process is an empty string, returns the string ".".
See also Rob Pike, “Lexical File Names in Plan 9 or Getting Dot-Dot Right,” https://9p.io/sys/doc/lexnames.html
fn Split(path: str): (dir: str, file: str)
Splits path immediately following the final slash, separating it into a directory and file name component. If there is no slash in path, returns an empty dir and file set to path. The returned values have the property that path = dir+file.
fn Join(elem: ...str): str
Joins any number of path elements into a single path, separating them with slashes. Empty elements are ignored. The result is Cleaned. However, if the argument list is empty or all its elements are empty, returns an empty string.
fn Ext(path: str): str
Returns the file name extension used by path. The extension is the suffix beginning at the final dot in the final slash-separated element of path; it is empty if there is no dot.
fn Base(mut path: str): str
Returns the last element of path. Trailing slashes are removed before extracting the last element. If the path is empty, returns ".". If the path consists entirely of slashes, returns "/".
fn IsAbs(path: str): bool
Reports whether the path is absolute.
fn Dir(path: str): str
Returns all but the last element of path, typically the path's directory. After dropping the final element using [Split], the path is Cleaned and trailing slashes are removed. If the path is empty, returns ".". If the path consists entirely of slashes followed by non-slash bytes, returns a single slash. In any other case, the returned path does not end in a slash.