File system paths.

The path functions are system independent: backward slashes ('\') are treated as a forward slash to separate directories. Windows style root names like c:\ or //server are also recognised.

A list of paths can be separated with either a colon (:) or semi-colon (;).

A pathstd/os/path/path: V is created using the path functions. Use string to convert back to a normalized path string. A path consists of a root name (/, c:\), the directory (foo/bar) and finally the base name. The base name itself consists of the stem and the extension. The extension is always the part that follows the last occurence of a dot ('.') in the base name.

A pathstd/os/path/path: V is always normalized. For a sequence of directories, any empty directory or . directory is ignored. A directory followed by .. is also ignored – this is the Plan 9 interpretation of paths where .. is considered lexically. If parent directories should be resolved through symbolic links, the realpath function should be used (which has the iostd/core/io: E effect though).

A pathstd/os/path/path: V represents a file system path..

Add two paths together.
Keeps the root of p1 and discards the root name of p2.
"/a/" + "b/foo.txt" === "/a/b/foo.txt"
"/a/foo.txt" + "/b/bar.txt" === "/a/foo.txt/b/bar.txt"
"c:/foo" + "d:/bar" === "c:/foo/bar".

Return the first path if it is not empty, otherwise return the second one.

Is a path absolute?

Return the path to the currently executing application.

Return the base directory that contains the currently running application. First tries app-pathstd/os/path/app-path: () -> io path().nobasestd/os/path/nobase: (p : path) -> path; if that ends in the bin or exe directory it returns the parent of that directory.

Return the base name of a path (stem name + extension)
"/foo/bar.txt".path.basenamestd/os/path/basename: (p : path) -> string === "bar.txt"
"/foo".path.basenamestd/os/path/basename: (p : path) -> string === "foo".

Change the base name of a path.

Change the extension of a path.

Change the stem name of a path.

Combine multiple paths using (+).

Returns the current working directory.
Equal to ".".realpath.

If a path has no extension, set it to the provided one.

Return the directory part of a path (including the rootname) "/foo/bar.txt".path.dirnamestd/os/path/dirname: (p : path) -> string === "/foo"
"/foo".path.dirnamestd/os/path/dirname: (p : path) -> string === "/".

Return a list of all directory components (excluding the root but including the basename).
"/foo/bar/test.txt".path.dirpartsstd/os/path/dirparts: (p : path) -> list<string> === ["foo","bar","test.txt"].

Is a path empty?

Return the extension of path (without the preceding dot ('.'))
"/foo/bar.svg.txt".path.extnamestd/os/path/extname: (p : path) -> string === "txt".

Return the home directory of the current user.

Remove the basename and only keep the root and directory name portion of the path.
nobasestd/os/path/nobase: (p : path) -> path("foo/bar.ext".path) == "foo").

Remove the directory and root and only keep the base name (file name) portion of the path.
nodirstd/os/path/nodir: (p : path) -> path("foo/bar.ext".path) === "bar.ext".

Remove the extension from a path.

Return the last directory component name (or the empty string).
"c:/foo/bar/tst.txt".path.parentnamestd/os/path/parentname: (p : path) -> string === "bar".

Create a normalized pathstd/os/path/path: V from a path string.

Convert a path to the absolute path on the file system. The path is not required to exist on disk. However, if it exists any permissions and symbolic links are resolved fully.
".".realpath (to get the current working directory)
"/foo".realpath (to resolve the full root, like "c:/foo" on windows).

Convert a path to the absolute path on the file system.
The overload on a plain string is necessary as it allows for unnormalized paths with ".." parts. For example "/foo/symlink/../test.txt" may resolve to "/bar/test.txt" if symlink is a symbolic link to a sub directory of "/bar".

Is a path relative?

Show a path as a string.

Return the stem name of path.
"/foo/bar.svg.txt".path.extnamestd/os/path/extname: (p : path) -> string === "foo.svg".

Convert a pathstd/os/path/path: V to a normalized stringstd/core/string: V path.
If this results in an empty string, the current directory path "." is returned. "c:/foo/test.txt".path.string -> "c:/foo/test.txt"
"c:\foo\test.txt".path.string -> "c:/foo/test.txt"
"/foo//./bar/../test.txt".path.string -> "/foo/test.txt".

Return the temporary directory for the current user.

Return the OS specific directory separator ("/" or "\").

Parse a list of paths seperated by colon (':') or semi-colon (';')
Colon separated paths can be ambiguous with Windows style root names (c:\) In particular, a single letter path followed by an absolute path, e.g. c:/foo:/bar is parsed as c:/foo and /bar.

Return the OS specific path separator (';' or ':').