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.

primitive val Path

Constructors

create

new val create()
: Path val^

Returns


Public Functions

is_sep

Determine if a byte is a path separator.

fun box is_sep(
  c: U8 val)
: Bool val

Parameters

  • c: U8 val

Returns


sep

Return the path separator as a string.

fun tag sep()
: String val

Returns


is_abs

Return true if the path is an absolute path.

fun box is_abs(
  path: String val)
: Bool val

Parameters

Returns


join

Join two paths together. If the next_path is absolute, simply return it. The returned path will be cleaned.

fun box join(
  path: String val,
  next_path: String val)
: String val

Parameters

Returns


clean

Replace multiple separators with a single separator. Convert / to the OS separator. Remove instances of . from the path. Remove instances of .. and the preceding path element from the path. The result will have no trailing slash unless it is a root directory. If the result would be empty, "." will be returned instead.

fun box clean(
  path: String val)
: String val

Parameters

Returns


normcase

Normalizes the case of path for the runtime platform.

fun box normcase(
  path: String val)
: String val

Parameters

Returns


cwd

Returns the program's working directory. Setting the working directory is not supported, as it is not concurrency-safe.

fun box cwd()
: String val

Returns


abs

Returns a cleaned, absolute path.

fun box abs(
  path: String val)
: String val

Parameters

Returns


rel

Returns a path such that Path.join(to, Path.rel(to, target)) == target. Raises an error if this isn't possible.

fun box rel(
  to: String val,
  target: String val)
: String val ?

Parameters

Returns


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

fun box split(
  path: String val,
  separator: String val = seq)
: (String val , String val)

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.

fun box base(
  path: String val,
  with_ext: Bool val = seq)
: String val

Parameters

Returns


dir

Return a cleaned path before the last separator, or the whole path if there is no separator.

fun box dir(
  path: String val)
: String val

Parameters

Returns


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.

fun box ext(
  path: String val)
: String val

Parameters

Returns


volume

On Windows, this returns the drive letter or UNC base at the beginning of the path, if there is one. Otherwise, this returns an empty string.

fun box volume(
  path: String val)
: String val

Parameters

Returns


from_slash

Changes each / in the path to the OS specific separator.

fun box from_slash(
  path: String val)
: String val

Parameters

Returns


to_slash

Changes each OS specific separator in the path to /.

fun box to_slash(
  path: String val)
: String val

Parameters

Returns


canonical

Return the equivalent canonical absolute path. Raise an error if there isn't one.

fun box canonical(
  path: String val)
: String val ?

Parameters

Returns


is_list_sep

Determine if a byte is a path list separator.

fun box is_list_sep(
  c: U8 val)
: Bool val

Parameters

  • c: U8 val

Returns


list_sep

Return the path list separator as a string.

fun box list_sep()
: String val

Returns


split_list

Separate a list of paths into an array of cleaned paths.

fun box split_list(
  path: String val)
: Array[String val] iso^

Parameters

Returns


random

Returns a pseudo-random base, suitable as a temporary file name or directory name, but not guaranteed to not already exist.

fun box random(
  len: USize val = seq)
: String val

Parameters

Returns


eq

fun box eq(
  that: Path val)
: Bool val

Parameters

Returns


ne

fun box ne(
  that: Path val)
: Bool val

Parameters

Returns


Private Functions

_drive_letter

Look for a drive letter followed by a ':', returning true if we find it.

fun box _drive_letter(
  path: String val,
  offset: ISize val = seq)
: Bool val

Parameters

Returns


_network_share

Look for a host, a \, and a resource. Return the path up to that point if we found one, otherwise an empty String.

fun box _network_share(
  path: String val,
  offset: ISize val = seq)
: String val

Parameters

Returns