Unifies AbsFileName with the the absolute filename that corresponds to the relative file specification RelFileSpec.
A valid file specification. See below for details.
Corresponding absolute filename.
A list of zero or more of the following. The default is the empty list:
'.pl') that should be tried when constructing the absolute file name. The extensions are tried in the order they appear in the list. Default value is Ext = [”], i.e. only the given FileSpec is tried, no extension is added. To specify
extensions()is equal to not giving any extensions option at all.
extensions(Ext)will be more portable between operating systems. This extension mechanism has no effect if FileSpec contains a file extension. Type must be one of the following atoms:
extensions(['']). FileSpec is a file without any extension. (Default)
extensions(['.pro','.pl','']). FileSpec is a Prolog source file, maybe with a ‘.pro’ or ‘.pl’ extension.
extensions(['.po']). FileSpec is a Prolog object file.
extensions(['.sav','']). FileSpec is a saved-state, maybe with a ‘.sav’ extension.
extensions(['']). This option has two effects. First, for an access option other than
access(none)the file must exist and be a directory. Second, the returned file name will end in slash (
Only when this option is present can
return the name of an existing directory with an access option other
access(none) without raising an exception.
file_type/1, .... The special children . and .. will never be returned.
The Glob should be an atom specifying a glob pattern consisting of characters interpreted as follows:
Please note: Currently glob pattern matching is case sensitive, even under Windows (where all expanded file names are subjected to case-normalization). This means that a pattern containing upper case Latin 1 characters or lower case non-Latin 1 characters will never match a file name under Windows. This may be corrected in the future.
With the options
this can be used to enumerate the contents of a directory.
access(none)is specified then a permission error is signaled unless
file_type(directory)is also specified.
Each atom must be one of the following:
file_type(directory)is also specified.
file_type(directory)is also specified.
Please note: Most current file systems have complex access control mechanisms, such as access control lists (ACLs). These mechanisms makes it hard to determine the effective access permissions, short of actually attempting the file operations in question. With networked file systems it may in fact be impossible to determine the effective access rights.
Therefore, a simplified access control model is used by
absolute_file_name/3 and elsewhere in SICStus.
On UNIX systems only the “classical” access control information is used, i.e. the read/write/execute “bits” for owner/group/other.
Under Windows only the “FAT” access control information is used, i.e.
a file may be marked as read-only.
A file is deemed executable if its extension is one of .cmd,
.bat or if it is classified as an executable by the Win32 API
This may change to more faithfully reflect the effective permissions
in a future release.
accessoption. This is the default if the Prolog flag
fileerrorsis set to its default value,
fileerrorsis set to
'', file names will be treated as relative to the current working directory. If a regular, existing file is given, file names will be treated as relative to the directory containing FileOrDirectory. Otherwise, file names will be treated as relative to FileOrDirectory.
absolute_file_name/3 is called from a goal in a file
being loaded, the default is the directory containing that file,
accessible from the load context (
Otherwise, the default is the current working directory.
You can use
file_systems:current_directory/1 to obtain the
current working directory from a goal in a file being loaded.
If FileSpec is
user, then AbsFileName is
user; this “file name” stands for the
standard input or output stream, depending on context. Otherwise,
unifies AbsFileName with the first absolute file name that
corresponds to the relative file specification FileSpec and
that satisfies the access modes given by Options.
The functionality of
is most easily described as multi-phase process, in which each phase
gets an infile from the preceding phase, and constructs one or more
outfiles to be consumed by the succeeding phases. The phases are:
The first phase and each of the expansion phases modifies the infile and produces variants
that will be fed into the succeeding phases. The functionality of all
phases but the first are decided with the option list. The last
phase checks if the generated file exists, and if not asks for a new
variant from the preceding phases. If the file exists, but doesn't obey
the access mode option, a permission exception is raised. If the file
obeys the access mode option,
absolute_file_name/3 commits to
that solution, subject to the
solutions option, and unifies
AbsFileName with the file name. For a thorough description, see
Note that the relative file specification FileSpec may also be of the form Path(FileSpec), in which case the absolute file name of the file FileSpec in one of the directories designated by Path is returned (see the description of each phase below).
relative_tooption. There can be more than one solution, in which case the outfile becomes the solutions in the order they are generated. If the following phases fails, and there are no more solutions, an existence exception is raised.
FileSpec can be a file search path,
library('lists.pl'). It can also refer to system properties, environment
variables and the home directory of users. See ref-fdi-syn, for a
description of syntactic rewriting.
glob/1option was specified all matching children of the directory will be enumerated. See the
file_type(directory)is specified, the file is suffixed with slash. Otherwise, trailing slash will be removed except for root directories, such as ‘/’ under UNIX or ‘c:/’ under Windows.
Can find multiple solutions only if the
If an option is specified more than once the rightmost option takes
precedence. This provides for a convenient way of adding default
values by putting these defaults at the front of the list of options.
absolute_file_name/3 succeeds, and the file access option was one
append}, it is
that the file can be
open/[3,4]. If the access option was
exist, the file
does exist, but might be both read and write protected.
file_type(directory) is not given,
the file access option is other than
a specified file refers to a directory, then
absolute_file_name/3 signals a permission error.
absolute_file_name/[2,3] is sensitive to the
Prolog flag, which determines whether the predicate should fail or
raise permission errors when encountering files with the wrong
permission. Failing has the effect that the search space always is
If RelFileSpec contains ‘..’ components, these are resolved
by removing directory components from the pathname, not by acessing
the file system. This can give unexpected results, e.g. when soft
links or mount points are involved.
This predicate is used for resolving file specification by built-in predicates that open files.
To check whether the file my_text exists in the home directory, with one of the extensions ‘.text’ or ‘.txt’, and is both writable and readable:
| ?- absolute_file_name('~/my_text', File, [extensions(['.text','.txt']), access([read,write])]).
To check whether the directory bin exists in the home directory:
| ?- absolute_file_name('~/bin', Dir, [file_type(directory), access(exist)]).
Here Dir would get a slash terminated value, such as
To list all files in the current directory:
| ?- findall(File, absolute_file_name('.', File, [glob('*'), solutions(all), file_errors(fail)]), Files).
To list all directories in the parent of the current directory containing the string “sicstus”:
| ?- findall(File, absolute_file_name('..', File, [glob('*sicstus*'),file_type(directory), solutions(all), file_errors(fail)]), Files).
To find a file cmd.exe in any of the “usual places” where
executables are found, i.e. by looking through the
| ?- absolute_file_name(path('cmd.exe'), File, [access(exist)]).
This uses the predefined file search path
 To the extent that the access permissions can be precisely determined. See the
access/1 option above.