read
, write
, append
, execute
,
search
, exist
, or none
. Fails
silently otherwise.
File may also be the name of a directory.
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.
The mode execute
is only intended for use with regular
files and the mode search
only with directories. However,
the two modes are currently equivalent and both can be used with either
files or directories. This may change in the future, so the results of
checking execute
access on directories or search
access on regular files should not be relied on.
The behaviour is backed up by the POSIX access() API. The Windows replacement (_waccess()) returns incorrect results because it does not consider ACLs (Access Control Lists). The Prolog flag win_file_access_check may be used to control the level of checking performed by Prolog. Please note that checking access never provides a guarantee that a subsequent open succeeds without errors due to inherent concurrency in file operations. It is generally more robust to try and open the file and handle possible exceptions. See open/4 and catch/3.