This module provides additional operations on files. This covers both more obscure and possible non-portable low-level operations and high-level utilities.
Using these Prolog primitives is typically to be preferred over using operating system primitives through shell/1 or process_create/3 because (1) there are no potential file name quoting issues, (2) there is no dependency on operating system commands and (3) using the implementations from this library is usually faster.
now
to indicate the current time. Defined options are:
link()
)
or removing (unlink()
) names.Below are some example queries. The first retrieves the access-time, while the second sets the last-modified time to the current time.
?- set_time_file(foo, [access(Access)], []). ?- set_time_file(foo, [], [modified(now)]).
hard
or symbolic
.
With some limitations, these functions also work on Windows. First of all, the underlying filesystem must support links. This requires NTFS. Second, symbolic links are only supported in Vista and later.
domain_error(link_type, Type)
if the requested link-type is
unknown or not supported on the target OS.?- relative_file_name('/home/janw/nice', '/home/janw/deep/dir/file', Path). Path = '../../nice'. ?- relative_file_name(Path, '/home/janw/deep/dir/file', '../../nice'). Path = '/home/janw/nice'.
Add a terminating /
to get a path relative to a directory,
e.g.
?- relative_file_name('/home/janw/deep/dir/file', './', Path). Path = 'deep/dir/file'.
All | paths must be in canonical POSIX notation, i.e., using / to separate segments in the path. See prolog_to_os_filename/2. |
atom_concat(Directory, File, Path)
,
but it ensures there is exactly one / between the two parts. Notes:
true
(default false
), recurse into
subdirectoriestrue
(default), follow symbolic links.fail
, warning
or error
.
Default is warning
. Errors notably happen if a
directory is unreadable or a link points nowhere.true
(default), also return hidden files.This predicate is safe against cycles introduced by symbolic links to directories.
The idea for a non-deterministic file search predicate comes from Nicos Angelopoulos.
+Mode
, -Mode
or a plain Mode, which adds new permissions, revokes
permissions or sets the exact permissions. Mode itself is an
integer, a POSIX mode name or a list of POSIX mode names. Defines names
are suid
,
sgid
, svtx
and all names defined by the
regular expression
[ugo]*[rwx]*
. Specifying none of "ugo" is the same as
specifying all of them. For example, to make a file executable for the
owner (user) and group, we can use:
?- chmod(myfile, +ugx).