Skip to main content

Get the last path component (file.path.last_component)

Declaration​

last_component, err = file.path.last_component(path)

Parameters​

  • path
    String. The path string.

Returns​

  • last_component
    String or nil. Returns the last path component on success, or nil if the path is invalid.
  • err
    String. Returns "Invalid path" if the path is invalid.

Description​

Return the last path component. For the root directory /, return /.
This function is available only in versions released after 20250914.

Example​

local last = file.path.last_component("/usr/local/bin") -- Returns "bin"
local root = file.path.last_component("/") -- Returns "/"