Module file

This module provides some basic file operations. The implementation is backed by some Java code that delivers some primitives to access files. The Prolog text invokes absolute_file_name/[2,3] before accessing these primitives. The result is that file name resolution and encoding is applied for these primitives and that they accept URIs.

Example:
?- directory_file('file:/C:/Program+Files/Java/', X).
X = 'jdk1.6.0_45/' ;
X = 'jdk1.7.0_67/' ;
X = 'jdk1.8.0_20/' ;
Etc..

The predicate directory_file/2 will enumerate direct sub directories and directly contained files. The predicate archive_file/3 will enumerate direct sub directories obtained from grouping file name segments and directly contained files. Both predicates will indicate a found sub directory by appending a slash (/).

Currently only URIs of protocol “file:” are supported. But future implementations might support further protocols such as “jar:” or service based protocols such as Google Drive, DropBox or others. The realization might depend on the platform, so that the Swing variant and Android might support different protocols in the future.

The following file predicates are provided:

make_name(B, E, N):
If B or E is a variable then the predicate succeeds when B and E unify with the base name and the extension respectively of the file name N. Otherwise the predicates succeeds when N unifies with the constructed name.
make_path(D, N, P):
If D or N is a variable then the predicate succeeds when D and N unify with the direc-tory and the name respectively of the path P. Otherwise the predicates succeeds when P unifies with the constructed path.
create_file(F):
Succeeds when the file F could be created.
delete_file(F):
Succeeds when the file or directory F could be deleted.
rename_file(F, G):
Succeeds when the file or directory F could be renamed to the file or directory G.
exists_file(F):
Succeeds when the file F exists and when it isn't a directory.
exists_directory(F):
Succeeds when the file F exists and when it is a directory.
make_directory(F):
The predicate succeeds when the directory F could be created.
directory_file(F, N):
Succeeds whenever N unifies with an entry if the directory F.
get_time_file(F, T):
Succeeds when T unifies with the last modified date of the file or directory F. T is measured in milliseconds since the epoch.
set_time_file(F, T):
Succeeds when the last modified date of the file or directory F could be set to T. T is measured in milliseconds since the epoch but might be rounded by the system.
is_relative_path(P):
The predicate succeeds when the path P is a relative path.
follow_path(B, R, A):
If R is a variable then the predicate succeeds when R unifies with the relative or abso-lute path that leads from B to A. Otherwise the predicate succeeds when A unifies with the path that results from B by following R.
canonical_path(P, C):
The predicate succeeds when C unifies with the canonical path of P.
getenv(N, V):
The predicate succeeds for the value V of the environment variable named N.
archive_file(F, P, N):
Succeeds whenever N unifies with an entry for the prefix P in the archive F.
exists_entry(F, N):
Succeeds when the entry N exists in the archive F.
make_pack(N, V, P):
If N or V is a variable then the predicate succeeds when N and V unify with the name and version of the package name P. Otherwise the predicate succeeds when P unifies with the constructed package name.

Kommentare