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.
- set_time_file(+File, -OldTimes, +NewTimes) is det
- Query and set POSIX time attributes of a file. Both OldTimes and
NewTimes are lists of option-terms. Times are represented in
SWI-Prolog's standard floating point numbers. New times may be
nowto indicate the current time. Defined options are:
- Describes the time of last access of the file. This value can be read and written.
- Describes the time the contents of the file was last modified. This value can be read and written.
- Describes the time the file-structure itself was changed by
link()) or removing (
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)]).
- link_file(+OldPath, +NewPath, +Type) is det
- Create a link in the filesystem from NewPath to OldPath. Type
defines the type of link and is one of
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.
- relative_file_name(+Path:atom, +RelToFile:atom, -RelPath:atom) is det
- relative_file_name(-Path:atom, +RelToFile:atom, +RelPath:atom) is det
- True when RelPath is Path, relative to the file RelToFile. Path and
RelTo are first handed to absolute_file_name/2, which makes the
absolute and canonical. Below are two examples:
?- 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'.
The following predicates are exported, but not or incorrectly documented.