text.paths
join paths and take them apart: folder, file name, extension
A path is text like /home/ada/notes.txt. These functions join paths and take them apart without touching the disk, so they work on paths that don’t exist.
Tags: parsing
path_joinjoin pieces into one path, with / or \ between them as your system usesbasenamethe last part of a path, usually the file name, or nildirnameeverything before the last part of a path, usually its folder, or nilextthe file’s extension without the dot, like “gz”, or nil if it has nonestemthe file name without its last extension, or nil
Functions
Section titled “Functions”path_join
Section titled “path_join”path_join(a: str, *more: str) -> str
join pieces into one path, with / or \ between them as your system uses
1path_join("a", "b.txt")"a/b.txt"Example outputCtrl+Enter to run
basename
Section titled “basename”basename(path: str) -> str|nil
the last part of a path, usually the file name, or nil
1"a/b/c.txt".basename"c.txt"Example outputCtrl+Enter to run
dirname
Section titled “dirname”dirname(path: str) -> str|nil
everything before the last part of a path, usually its folder, or nil
1"a/b/c.txt".dirname"a/b"Example outputCtrl+Enter to run
See also basename
ext(path: str) -> str|nil
the file’s extension without the dot, like “gz”, or nil if it has none
1"a/b.tar.gz".ext"gz"2"README".extnilExample outputCtrl+Enter to run
See also stem
stem(path: str) -> str|nil
the file name without its last extension, or nil
1"a/b.tar.gz".stem"b.tar"Example outputCtrl+Enter to run
More examples
Section titled “More examples”1# a file name without, and then only, its extension2["a/b.tar.gz".stem, "a/b.tar.gz".ext]["b.tar", "gz"]Example outputCtrl+Enter to run
Example results generated on 2026-11-04. Ones using now, today or randomness will differ when you run them.