Base may have a library/1 wrapper around the name. If this is used, the file is searched for in the directories specified in library path (including any subdirectory with the same name as given in the library/1 wrapper, i.e. we check for both lib/foo.eco and lib/foo/foo.eco). The search order is the order in which the library directories appear in the library_path flag of get_flag/2, and for each directory, the completions are tried in the order in which they appear in the list Completions. All matching files are returned via backtracking. If only the first one is required, use once/1.
MatchedFile is the same type as Base (atom or string). Also, if Base is a relative (absolute) pathname, then so is MatchedFile. If Base starts with '~' or enviroment variables (specified with a leading '$'), these are substituted. If the library(...) wrapper is used, the proper library path is substituted. Note that the executable permission for Windows may be approximate, because Windows (especially Vista) has a different system for dealing with execute permission.
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 ; get_flag(prolog_suffix, Sufs), (existing_file(Rel, Sufs, , ExtRel) -> true ; ExtRel = Rel), canonical_path_name(ExtRel, Abs) ).
Success: % Trying different file extensions, including the empty one: ?- existing_file("hello", [".ecl",".txt",""], , File). File = "hello.txt" More? (;) No (0.00s cpu) % assuming hello.ecl and hello do not exist % Looking for one of several files in the parent directory: ?- existing_file("../", ["a.txt","b.txt","c.txt"], [readable], File). File = "../a.txt" More? (;) File = "../c.txt" More? (;) No (0.00s cpu) % assuming b.txt does not exist or is not readable % Looking for a precompiled library: ?- existing_file(library(fd), [".eco"], [readable], File). File = '/homes/ks15/Eclipse/lib/fd.eco' More? (;) No (0.00s cpu) % Looking for source files: ?- get_flag(prolog_suffix, Exts), existing_file("hello", Exts, [readable], File). File = "hello.ecl" More? (;) No (0.00s cpu) % Looking for different file names: [eclipse 1]: existing_file(test, [1,2,3], , File). File = test1 More? (;) File = test3 More? (;) No (0.00s cpu) Failure: [eclipse 1]: existing_file(library(fd), , [readable], File). % no Completions at all; will always fail [eclipse 1]: existing_file(library(fd), [""], [readable], File). % no library file with just 'fd' as the name (file has a suffix)