This is a bit of a mixture between fish and fowl
Nothing on the path needs to exist, so in that case it's a purely syntactic operation (no verification against the actual filesystem state is made):
?- absolute_file_name('/a/b/c/d',Abs). Abs = '/a/b/c/d'. ?- absolute_file_name('/a/b/c/d',Abs,[file_type(prolog)]). Abs = '/a/b/c/d.pl'.
But if one specifies "directory", as Wouter Beek says, a check is made:
?- absolute_file_name('////usr/local/logic/swipl/bin/../lib/swipl/bin/x86_64-linux/',Abs, [file_type(directory)]). Abs = '/usr/local/logic/swipl/lib/swipl/bin/x86_64-linux/'. ?- absolute_file_name('////usr/local/logic/swipl/bin/../lib/swipl/bin/x86_64-linux/foo',Abs, [file_type(directory)]). ERROR: source_sink `'////usr/local/logic/swipl/bin/../lib/swipl/bin/x86_64-linux/foo'' does not exist ?- absolute_file_name('////usr/local/logic/swipl/bin/../lib/swipl/bin/x86_64-linux/swipl',Abs, [file_type(directory)]). ERROR: directory `'////usr/local/logic/swipl/bin/../lib/swipl/bin/x86_64-linux/swipl'' does not exist (is not a directory)
Somehow this feels lopsided.
Note that this predicate does not resolve symlinks to their actual canonical path.
It also leaves a final '/', even if there is a file there matching the name:
?- absolute_file_name('/usr/local/logic/swipl/bin/../lib/swipl/bin/x86_64-linux/swipl/',Abs). Abs = '/usr/local/logic/swipl/lib/swipl/bin/x86_64-linux/swipl/'.