read
, write
, append
, exist
, none
or
execute
. File may also be the name of a
directory. Fails silently otherwise. access_file(File, none)
simply succeeds without testing anything.
If `Mode' is write
or append
, this
predicate also succeeds if the file does not exist and the user has
write-access to the directory of the specified location.
/
. There are two special
cases. The directory-name of /
is /
itself and the directory-name if File does not contain any /
characters is .
..
and ..
are deleted.
This predicate ensures that expanding a file-name it returns the same
absolute path regardless of how the file is addressed. SWI-Prolog uses
absolute file names to register source files independent of the current
working directory. See also absolute_file_name/3.
See also
absolute_file_name/3
and expand_file_name/2.''
. For each
extension, absolute_file_name/3
will first add the extension and then verify the conditions imposed by
the other options. If the condition fails, the next extension of the
list is tried. Extensions may be specified both as ..ext
or
plain ext
.read
, write
, append
, exist
or none
. See also access_file/2.txt
implies ['']
,
prolog
implies ['.pl', '']
, executable
implies
['.so', '']
, qlf
implies ['.qlf', '']
and
directory
implies ['']
. The file-type source
is an alias for prolog
for compatibility with SICStus
Prolog. See also prolog_file_type/2.error
(default), throw and existence_error
exception if the file cannot be found. If fail
, stay
silent.62Silent operation was the
default up to version 3.2.6.first
(default), the predicates leaves no choice-point.
Otherwise a choice-point will be left and backtracking may yield more
solutions.true
(default is false
) and Spec
is atomic, call expand_file_name/2
followed by member/2
on Spec before proceeding. This is a SWI-Prolog extension.
The Prolog flag verbose_file_search
can be set to true
to help debugging Prolog's search for
files.
Compatibility considerations with common argument-order in ISO as
well as SICStus absolute_file_name/3
forced us to be flexible here. If the last argument is a list and the
2nd not, the arguments are swapped, making the call absolute_file_name(+Spec,
-Path, +Options)
valid as well.
<letter>:
.
This predicate is intended to provide platform-independent checking for
absolute paths. See also absolute_file_name/2
and prolog_to_os_filename/2..
).
If an Extension is generated, it will not have a leading dot..
and
..
. See also expand_file_name/2.63This
predicate should be considered a misnomer because it returns entries
rather than files. We stick to this name for compatibility with e.g.,
SICStus, Ciao and YAP.?
',
`*
', `[ ... ]
' and `{...}
'
are recognised. The interpretation of `{...}
' is
interpreted slightly different from the C shell (csh(1)). The comma
separated argument can be arbitrary patterns, including `{...}
'
patterns. The empty pattern is legal as well: `{.pl,}
'
matches either `.pl
' or the empty string.
If the pattern does contains wildcard characters, only existing files and directories are returned. Expanding a `pattern' without wildcard characters returns the argument, regardless on whether or not it exists.
Before expanding wildcards, the construct $var
is expanded to the value of the environment variable var and
a possible leading ~
character is expanded to the user's
home directory.64On Windows, the
home directory is determined as follows: if the environment variable HOME
exists, this is used. If the variables HOMEDRIVE
and HOMEPATH
exist (Windows-NT), these are used. At initialisation, the system will
set the environment variable HOME
to point to the
SWI-Prolog home directory if neither HOME
nor HOMEPATH
and HOMEDRIVE
are defined.
Because it is possible to guess the generated filename, attackers may create the filesystem entry as a link and possibly create a security issue. New code should use tmp_file_stream/3.
binary
. Stream is the output stream. If the OS
supports it, the created file is only accessible to the current user. If
the OS supports it, the file is created using the open()-flag O_EXCL
,
which guarantees that the file did not exist before this call. This
predicate is a safe replacement of tmp_file/2.
Note that in those cases where the temporary file is needed to store
output from an external command, the file must be closed first. E.g.,
the following downloads a file from a URL to a temporary file and opens
the file for reading (On Unix systems you can delete the file after
opening it for reading for cleanup):
open_url(URL, In) :- tmp_file_stream(text, File, Stream), close(Stream), process_create(curl, ['-o', File, URL], []), open(File, read, In), delete_file(File). % Unix-only
Temporary files created using this call are removed if the Prolog process terminates. Calling delete_file/1 using FileName removes the file and removes the entry from the administration of files-to-be-deleted.
working_directory(CWD, CWD)
to get the current directory.
See also absolute_file_name/2
and chdir/1.bugSome
of the file-I/O predicates use local filenames. Changing directory while
file-bound streams are open causes wrong results on telling/1, seeing/1
and current_stream/3
Note that the working directory is shared between all threads.