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.

Available since: v0.0.1
Arguments
#NameTypeFallback
fileSystemPathstring
extensionToRemovestring?
Return values
#NameType
basenamestring

path.dirname

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

Available since: v0.0.1
Arguments
#NameTypeFallback
fileSystemPathstring
Return values
#NameType
dirnamestring

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).

Available since: v0.0.1
Arguments
#NameTypeFallback
fileSystemPathstring
Return values
#NameType
extnamestring

path.isAbsolute

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

Available since: v0.0.1
Arguments
#NameTypeFallback
fileSystemPathstring
Return values
#NameType
isAbsolutePathboolean

path.join

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

Available since: v0.0.1
Arguments
#NameTypeFallback
...varargs
Return values
#NameType
normalizedFileSystemPathstring

path.normalize

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

Available since: v0.0.1
Arguments
#NameTypeFallback
fileSystemPathstring
Return values
#NameType
normalizedFileSystemPathstring

path.relative

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

Available since: v0.0.1
Arguments
#NameTypeFallback
fromstring
tostring
Return values
#NameType
relativeFileSystemPathstring

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).

Available since: v0.0.1
Arguments
#NameTypeFallback
...varargs
Return values
#NameType
absoluteResolvedFileSystemPathstring

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