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
| Function | Description |
|---|---|
path.is_absolute(p) → bool | True for POSIX-absolute, Windows drive paths, and UNC paths. |
path.dirname(p) → string | Everything before the last separator. |
path.basename(p) → string | Last component (file or directory name). |
path.stem(p) → string | basename minus the last extension. |
path.extname(p) → string | The last extension including the dot (e.g. ".log"). |
path.join(parts) → string | Concatenate a list of segments with /. |
path.normalize(p) → string | Collapse . and .. segments; squash duplicate separators. |
path.sep → string | Native separator ("/" on POSIX, "\\" on Windows). |
See also
io— read, write, and inspect the files those paths point at.