Inherited from v1.0.0

path module

Build, split, and normalize filesystem paths in a portable way. Accepts both / and \ on input; emits / (which works on Windows too).

import "path" as path;

print(path.join(["data", "users", "alice.json"]));   // data/users/alice.json
print(path.basename("/var/log/app.log"));            // app.log
print(path.normalize("/foo/./bar/../baz"));          // /foo/baz

API

FunctionDescription
path.is_absolute(p) → boolTrue for POSIX-absolute, Windows drive paths, and UNC paths.
path.dirname(p) → stringEverything before the last separator.
path.basename(p) → stringLast component (file or directory name).
path.stem(p) → stringbasename minus the last extension.
path.extname(p) → stringThe last extension including the dot (e.g. ".log").
path.join(parts) → stringConcatenate a list of segments with /.
path.normalize(p) → stringCollapse . and .. segments; squash duplicate separators.
path.sep → stringNative separator ("/" on POSIX, "\\" on Windows).

See also

  • io — read, write, and inspect the files those paths point at.