Skip to main content

path

Lua port of the NodeJS path library

Status

Stable: Functionality is covered by semantic versioning guarantees and unlikely to see breaking changes

Availability

This module is preloaded. You can simply require it:

local path = require("path")

It's also available as a global alias.

Functions

path.basename

Returns the filename and extension of the given fileSystemPath (ignoring trailing separators), similar to the Unix basename command.

If an extension is also given, the matched component (case-sensitive) will be stripped from the result before returning it.

path.dirname

Returns the directory path of the given fileSystemPath (ignoring trailing separators), similar to the Unix dirname command.

path.extname

Returns the file extension of the given fileSystemPath. This is an empty string if the given file has no extension (or is a directory).

path.isAbsolute

Returns true if the given fileSystemPath is an absolute (fully-qualified) path, and false otherwise.

path.join

Returns the normalized fileSystemPath constructed from the given path segments and the platform-specific path separator.

path.normalize

Returns the normalized fileSystemPath after resolving . and .. segments. Preserves trailing separators, but removes duplicates.

path.relative

Returns the relative path from from to to based on the current working directory.

path.resolve

Returns the fileSystemPath constructed by resolving a sequence of paths (or path segments) to create an absolute path.

This is conceptually similar to running a sequence of cd commands and writing down the end result (i.e., where you landed).

Tables

path.posix

POSIX-specific version that is preloaded automatically on Linux and Mac OS, but can be accessed explicitly on Windows.

That is to say, if you're on Linux (or Mac OS) then path is always equal to path.posix, but you can still use the path.win32 APIs.

path.win32

Windows-specific version that is preloaded automatically on Windows, but can be accessed explicitly on other platforms.

That is to say, if you're on Windows then path is always equal to path.win32, but you can still use the path.posix APIs.

Changelog

VersionWhat happened?
v0.0.1Initial release