Skip to main content

Append a path component (file.path.add_component)

Declaration​

new_path, err = file.path.add_component(path, component)

Parameters​

  • path
    String. The base path string.
  • component
    String. The path component to append.

Returns​

  • new_path
    String or nil. Returns the path string with the component appended on success, or nil if the path or component is invalid.
  • err
    String. Returns "Invalid path" if the path or component is invalid.

Description​

Append the specified component to the base path, automatically handling the / separator at the join.
This function only generates a path string; it does not create any actual file or directory.
This function is available only in versions released after 20250914.

Example​

local full_path = file.path.add_component("/usr/local", "bin") -- Returns "/usr/local/bin"
local tmp_path = file.path.add_component("/", "tmp") -- Returns "/tmp"