pPath provides functions for working with paths.
This module is intended for LÖVE's virtual filesystem paths. As such, its functions assume that all paths use / as directory separators, and they are not aware of . and ...
Dependencies: None.
local pPath = require("p_path")
local my_path = pPath.join("foo", "bar") --> "foo/bar"
API
pPath.getExtension
Gets the extension at the end of a file path.
local ext = pPath.getExtension(path)
-
path: The file path.
Returns: The extension (including the dot), or an empty string if the path did not end with an extension.
Notes
When the file path ends with multiple extensions, like my_file.txt.zip, only the last part (.zip) is returned.
pPath.join
Joins two path fragments.
local joined = pPath.join(a, b)
-
a: The first path fragment. -
b: The second path fragment.
Returns: The joined path.
Notes
This function:
-
Adds a slash between
aandb, whenais not an empty string. -
Removes leading and trailing slashes.
-
Does not remove multiple consecutive slashes within fragments, like
foo//bar.
pPath.splitPathAndExtension
Splits the extension from a file path.
local main, ext = pPath.splitPathAndExtension(path)
-
path: The file path.
Returns: The main path component and the extension (or an empty string if there was no extension).
VERSION: 2.106