std.path
API summary (generated from the Beans source by npm run coverage): 5 package functions.
std.path works on path strings only. It never touches the filesystem, and it
always uses / as the separator on every supported target. Think of it as string
math for paths. Read the source at
stdlib/std/path/path.b.
import std.pathpub fn join(first: string, second: string) -> stringpub fn parent(value: string) -> stringpub fn name(value: string) -> stringpub fn extension(value: string) -> stringpub fn stem(value: string) -> stringjoinputs exactly one/between the two parts and skips empty segments. Ifsecondis an absolute path (starts with/), it wins and is returned as-is.parentreturns everything before the last segment. Trailing slashes are ignored. It returns/for a root-level path and""when there is no parent.namereturns the final segment. Trailing slashes are ignored, soname("a/b/")is"b".extensionreturns the file extension including the leading dot, like".txt", or""if there is none. A dotfile such as.envis treated as a name, not an extension, so its extension is empty.stemreturns the final segment with its extension removed.stemandextensiontogether reconstructname.
import std.ioimport std.path
fn main() { io.println(path.join("a/b", "c.txt")) // a/b/c.txt io.println(path.join("a", "/etc")) // /etc io.println(path.parent("a/b/c.txt")) // a/b io.println(path.name("a/b/c.txt")) // c.txt io.println(path.extension("a/b/c.txt")) // .txt io.println(path.extension(".env")) // (empty) io.println(path.stem("a/b/c.txt")) // c}See also
Section titled “See also”- std.fs, read and write the files these paths point at.