path
Lua port of the NodeJS path library
Status
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.1Arguments | |||
---|---|---|---|
# | Name | Type | Fallback |
fileSystemPath | string | ||
extensionToRemove | string? |
Return values | ||
---|---|---|
# | Name | Type |
basename | string |
path.dirname
Returns the directory path of the given fileSystemPath
(ignoring trailing separators), similar to the Unix dirname command.
Arguments | |||
---|---|---|---|
# | Name | Type | Fallback |
fileSystemPath | string |
Return values | ||
---|---|---|
# | Name | Type |
dirname | string |
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).
Arguments | |||
---|---|---|---|
# | Name | Type | Fallback |
fileSystemPath | string |
Return values | ||
---|---|---|
# | Name | Type |
extname | string |
path.isAbsolute
Returns true
if the given fileSystemPath
is an absolute (fully-qualified) path, and false
otherwise.
Arguments | |||
---|---|---|---|
# | Name | Type | Fallback |
fileSystemPath | string |
Return values | ||
---|---|---|
# | Name | Type |
isAbsolutePath | boolean |
path.join
Returns the normalized fileSystemPath
constructed from the given path segments and the platform-specific path separator.
Arguments | |||
---|---|---|---|
# | Name | Type | Fallback |
... | varargs |
Return values | ||
---|---|---|
# | Name | Type |
normalizedFileSystemPath | string |
path.normalize
Returns the normalized fileSystemPath
after resolving .
and ..
segments. Preserves trailing separators, but removes duplicates.
Arguments | |||
---|---|---|---|
# | Name | Type | Fallback |
fileSystemPath | string |
Return values | ||
---|---|---|
# | Name | Type |
normalizedFileSystemPath | string |
path.relative
Returns the relative path from from
to to
based on the current working directory.
Arguments | |||
---|---|---|---|
# | Name | Type | Fallback |
from | string | ||
to | string |
Return values | ||
---|---|---|
# | Name | Type |
relativeFileSystemPath | string |
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).
Arguments | |||
---|---|---|---|
# | Name | Type | Fallback |
... | varargs |
Return values | ||
---|---|---|
# | Name | Type |
absoluteResolvedFileSystemPath | string |
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
Version | What happened? |
---|---|
v0.0.1 | Initial release |