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) ).
[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/'