Skip to main content

Normalize a path (file.path.normalize)

Declaration​

normalized_path, err = file.path.normalize(path)

Parameters​

  • path
    String. The original path string.

Returns​

  • normalized_path
    String or nil. Returns the normalized path string on success, or nil if the path is invalid.
  • err
    String. Returns "Invalid path" if the path is invalid.

Description​

Normalize the path by processing its . and .. components and removing redundant slashes.
To resolve symbolic links in a path, use file.path.resolve_symlinks.
This function does not move or rename any actual file or directory.
This function is available only in versions released after 20250914.

Example​

local std_path = file.path.normalize("/usr/local/../bin/./script") -- Returns "/usr/bin/script"
local clean_path = file.path.normalize("//tmp///file/") -- Returns "/tmp/file"