std/os/path▲toc

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 recognized.

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

A pathstd/os/path/path: V is created using the pathstd/os/path/path: (s : string) -> 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 occurrence 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).

type pathstd/os/path/path: V

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

Convenience function that adds a string path.

Convenience function that adds two strings into a path.

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".

Add two paths together using left-associative operator (/).
Keeps the root of p1 and discards the root name of p2.
"/a/" / "b/foo.txt" (===)std/core/sslice/(===): (slice1 : sslice, slice2 : sslice) -> bool "/a/b/foo.txt"
"/a/foo.txt" / "/b/bar.txt" (===)std/core/sslice/(===): (slice1 : sslice, slice2 : sslice) -> bool "/a/foo.txt/b/bar.txt"
"c:/foo" / "d:/bar" (===)std/core/sslice/(===): (slice1 : sslice, slice2 : sslice) -> bool "c:/foo/bar".

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

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.

Change the base name of a path.

Change the extension of a path. Only adds a dot if the extname does not already start with a dot.

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 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".pathstd/os/path/path: (s : string) -> 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".pathstd/os/path/path: (s : string) -> path) (===)std/core/sslice/(===): (slice1 : sslice, slice2 : sslice) -> bool "bar.ext".

Remove the extension from a path.

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).

Show a path as a string.

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

Return the temporary directory for the current user.

fun partsep(): ndetstd/core/types/ndet: X stringstd/core/types/string: V

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

fun paths( s : stringstd/core/types/string: V ) : liststd/core/types/list: V -> V<pathstd/os/path/path: V>

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.

fun pathsep(): ndetstd/core/types/ndet: X stringstd/core/types/string: V

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

private import std/core/typesstd/core/types, std/core/hndstd/core/hnd, std/core/exnstd/core/exn, std/core/boolstd/core/bool, std/core/orderstd/core/order, std/core/charstd/core/char, std/core/intstd/core/int, std/core/vectorstd/core/vector, std/core/stringstd/core/string, std/core/sslicestd/core/sslice, std/core/liststd/core/list, std/core/maybestd/core/maybe, std/core/eitherstd/core/either, std/core/tuplestd/core/tuple, std/core/showstd/core/show, std/core/debugstd/core/debug, std/core/delayedstd/core/delayed, std/core/consolestd/core/console, std/corestd/core, std/text/parsestd/text/parse