[ Operating System | Reference Manual | Alphabetic Index ]

canonical_path_name(+Path, -CanonicalPath)

Expand a path name into the full `canonical' form.
Path
A pathname (atom or string)
CanonicalPath
Canonical pathname for Path

Description

This predicate expands a given pathname, and converts it into the `canonical' form of the pathname. The following are done to the path:

Path does not need to exist, and only the removal of aliasing is performed on the part of the path that does exist.

CanonicalPath is always the same type as Path (string or atom). If Path is empty, it is replaced by the current working directory.

The predicates canonical_path_name/2 and existing_file/4 are intended as replacement for absolute_file_name/2 in previous releases. The functionality of completing an incomplete name and returning an absolute path of absolute_file_name/2 has been separated. The following approximately implements the old absolute_file_name/2:

    absolute_file_name(Rel, Abs) :-
	(Rel == user ->
	    Abs == user  % treat user specially
	; get_flag(prolog_suffix, Sufs),
	  (existing_file(Rel, Sufs, [], ExtRel) -> true ; ExtRel = Rel),
	  canonical_path_name(ExtRel, Abs)
        ).

Modes and Determinism

Exceptions

(5) type error
Path is not a string or atom.

Examples

      [eclipse]: canonical_path_name("file", Full).  %cwd is /homes/tom
      Full = "/homes/tom/file"
      yes

      [eclipse]: canonical_path_name(file, Full).
      Full = '/homes/tom/file'
      yes

      [eclipse]: canonical_path_name("~/file", Full).
      Full = "/homes/tom/file"
      yes

      [eclipse]: canonical_path_name('file/..', Full).
      Full = '/homes/tom/'

      [eclipse]: canonical_path_name('/users/tom', Full). 
      % /users/tom is a symbolic link for /homes/tom
      Full = '/homes/tom/'

See Also

existing_file / 4, os_file_name / 2, pathname / 4