Method System.normalize_path()


Method normalize_path

utf8_string normalize_path(utf8_string path)

Description

Normalize an existing MacOS X file system path.

The following transformations are currently done:

  • Relative paths are expanded to absolute paths.

  • Initial components "/private" and "/var/automount" (or both) are removed if the result indicates the same directory node.

  • Trailing slashes ('/') are removed.

  • Current- and parent-directory path components ("." and "..") are followed, similar to combine_path.

  • Case-information in directory and file names is restored.

  • File fork information is stripped (ie all stuff after the first non-directory in the path is stripped).

Returns

A normalized absolute path without trailing slashes.

May throw errors on failure, e.g. if the file or directory doesn't exist or if the path is not valid UTF-8.

See also

combine_path()


Method normalize_path

utf8_string normalize_path(string(8bit) path)

Description

Normalize an existing Windows file system path.

The following transformations are currently done:

  • If the path is not valid UTF-8, it will be converted into UTF-8.

  • Forward slashes ('/') are converted to backward slashes ('\').

  • Trailing slashes are removed, except a single slash after a drive letter (e.g. "C:\" is returned instead of "C:").

  • Extraneous empty extensions are removed.

  • Short filenames are expanded to their corresponding long variants.

  • Relative paths are expanded to absolute paths.

  • Current- and parent-directory path components ("." and "..") are followed, similar to combine_path.

  • Case-information in directory and file names is restored.

  • Drive letters are returned in uppercase.

  • The host and share parts of UNC paths are returned in lowercase.

Returns

A normalized absolute path without trailing slashes.

Throws errors on failure, e.g. if the file or directory doesn't exist.

Note

File fork information is currently not supported (invalid data).

Note

In Pike 7.6 and earlier, this function didn't preserve a single slash after drive letters, and it didn't convert the host and share parts of an UNC path to lowercase.

See also

combine_path(), combine_path_nt()