tur/path
pure path-string manipulation (join, dirname, basename, extension).
Since: Phase B1
path/join
(path/join [base :cstr segment :cstr] :cstr)
join two path segments with a single slash separator.
| base | the base path cstr | |
| segment | the 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
path/basename
(path/basename [p :cstr] :cstr)
return the last path component.
| p | path 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
path/dirname
(path/dirname [p :cstr] :cstr)
return the parent directory component.
| p | path 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
path/extension
(path/extension [p :cstr] :cstr)
return the file extension including the leading dot.
| p | path 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
path/stem
(path/stem [p :cstr] :cstr)
return the filename without its extension.
| p | path 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
path/absolute?
(path/absolute? [p :cstr] :bool)
test whether a path is absolute (starts with '/').
| p | path cstr |
true if p starts with '/', false otherwise.
(path/absolute? "/usr/bin") ; => true (path/absolute? "relative") ; => false
Since: Phase B2
path/normalize
(path/normalize [p :cstr] :cstr)
collapse redundant '.' and '..' segments in a path.
| p | path cstr |
A new heap-allocated normalized path cstr.
(path/normalize "/foo/../bar/./baz") ; => "/bar/baz"
Since: Phase B2