Pike v8.0 release 1738

Method System.normalize_path()


Method normalize_path

string(8bit) normalize_path(string(8bit) path)

Description

Normalize an existing Windows file system path.

The following transformations are currently done:

  • 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()