No matching definitions.

tur/path

stdlib/path.tur

pure path-string manipulation (join, dirname, basename, extension).

Since: Phase B1

defn

path/join

(path/join [base :cstr segment :cstr] :cstr)

join two path segments with a single slash separator.

basethe base path cstr
segmentthe path segment to append

A new heap-allocated cstr. Free when done. If base ends with '/' no extra separator is added.

(path/join "/usr" "local")  ; => "/usr/local"

Since: Phase B2

defn

path/basename

(path/basename [p :cstr] :cstr)

return the last path component.

ppath cstr

A new heap-allocated cstr containing the last component. Returns a copy of p if no slash is present.

(path/basename "/foo/bar.txt")  ; => "bar.txt"

Since: Phase B2

defn

path/dirname

(path/dirname [p :cstr] :cstr)

return the parent directory component.

ppath cstr

A new heap-allocated cstr of the parent directory. Returns "." if no directory component exists, "/" for the root.

(path/dirname "/foo/bar.txt")  ; => "/foo"

Since: Phase B2

defn

path/extension

(path/extension [p :cstr] :cstr)

return the file extension including the leading dot.

ppath cstr

A new heap-allocated cstr of the extension (e.g., ".txt"), or an empty string heap-copy if there is no extension.

(path/extension "/foo/bar.txt")  ; => ".txt"
  (path/extension "/foo/bar")      ; => ""

Since: Phase B2

defn

path/stem

(path/stem [p :cstr] :cstr)

return the filename without its extension.

ppath cstr

A new heap-allocated cstr of the stem. Equal to path/basename if there is no extension.

(path/stem "/foo/bar.txt")  ; => "bar"
  (path/stem "/foo/bar")      ; => "bar"

Since: Phase B2

defn

path/absolute?

(path/absolute? [p :cstr] :bool)

test whether a path is absolute (starts with '/').

ppath cstr

true if p starts with '/', false otherwise.

(path/absolute? "/usr/bin")  ; => true
  (path/absolute? "relative")  ; => false

Since: Phase B2

defn

path/normalize

(path/normalize [p :cstr] :cstr)

collapse redundant '.' and '..' segments in a path.

ppath cstr

A new heap-allocated normalized path cstr.

(path/normalize "/foo/../bar/./baz")  ; => "/bar/baz"

Since: Phase B2