On this page:
Path
Path
Path
Path.bytes
Path.string
8.12

6.42 Paths🔗ℹ

The . operator can be used on a path expression as equivalent to calling Path functions:

path.bytes()

 is 

Path.bytes(path)

path.string()

 is 

Path.string(path)

annotation

Path

Matches a path value.

function

fun Path(path :: Bytes || String || Path) :: Path

Constructs a path given a byte string, string, or existing path. When a path is provided as path, then the result is path.

> def p = Path("/home/rhombus/shape.txt")

> p

#<path:/home/rhombus/shape.txt>

> Path(p)

#<path:/home/rhombus/shape.txt>

> p.string()

"/home/rhombus/shape.txt"

binding operator

Path(bind)

Matches a path where the byte-string form of the path matches bind.

> def Path(p) = Path("/home/rhombus/shape.txt")

> p

#"/home/rhombus/shape.txt"

function

fun Path.bytes(path :: Path) :: Bytes

Converts a path to a byte-string form, which does not lose any information about the path.

> def p = Path("/home/rhombus/shape.txt")

> Path.bytes(p)

#"/home/rhombus/shape.txt"

> p.bytes()

#"/home/rhombus/shape.txt"

function

fun Path.string(path :: Path) :: String

Converts a path to a human-readable form, but the conversion may lose information if the path cannot be expressed using a string (e.g., due to a byte-string form that is not a UTF-8 encoding).

> def p = Path(#"/home/rhombus/shape.txt")

> Path.string(p)

"/home/rhombus/shape.txt"

> p.string()

"/home/rhombus/shape.txt"