Split a path into components (file.path.components)
Declaration
components, err = file.path.components(path)
Parameters
- path
String. The path string to split.
Returns
- components
Array (table) or nil. Returns an array of strings containing the path components on success, or nil if the path is invalid. - err
String. Returns"Invalid path"if the path is invalid.
Description
Split the path string into its components and return them in path order.
The root directory/of an absolute path is returned as a separate component.
This function is available only in versions released after 20250914.
Example
local components = file.path.components("/usr/local/bin")
-- Returns {"/", "usr", "local", "bin"}