Path Resolution

A relative path that is not wrapped into a compound is resolved against the current base in write or append mode. The current base is the Prolog flag “base_url”. Otherwise in read mode, if the call-site is not user it is resolved against the path of the call-site itself. In both cases the suffixes of the sys_add_file_extension/1 command are used:

Example:
?- absolute_file_name('my folder/my file', X).
Error: File 'my folder/my file' not found.
absolute_file_name/2

?- set_prolog_flag(base_url, '/C:/Users/Jan Burse/Desktop/').
Yes

?- sys_add_file_extension(text('.dcg', 'text/prolog')).
Yes

?- absolute_file_name('my folder/my file', X).
X = 'file:/C:/Users/Jan Burse/Desktop/my folder/my file.dcg'

Paths should not use a system specific directory separator but always use the forward slash (/). For convenience paths have an automatic prefixing of a schema. Paths starting with a double slash (//) are prefixed by the “http” schema. Paths starting with a single slash (/) are prefixed by the “file” schema. Drive letters are not considered schema.

If the path is wrapped into a compound and if the functor of the compound is either library/1, foreign/1 or verbatim/1 then the path is looked up in the class path. The class path can be updated and queried by the predicates sys_add_path/1 and sys_current_path/1. In these cases the prefixes of the package/1 and use_package/1 command are also used.

Write or append access resolution:
  <path>                    resolve <path> in base.
Read access resolution:
  library(<path>)           lookup resource <path> in class path.
  foreign(<path>) lookup class <path> in class path.
verbatim(<path>) like library(<path>) or take as is.
  <path>                    resolve <path> in scope or base.

The predicates absolute_file_name/[2,3] and absolute_resource_name/1 provide file name resolving. The predicate absolute_file_name/2 works bi-directionally. For a given already resolved path it will make a best effort attempt to reconstruct either a compound form foreign/1, library/1 or verbatim/1 or a relative path.

The following path resolution predicates are provided:

sys_add_path(R):
The predicate succeeds in adding the relative path R to the current class loader.
sys_current_path(A):
The predicate succeeds in A with the currently added absolute paths A along the class loaders.
sys_add_file_extension(E):
The predicate succeeds in adding the file extension database entry E to the current knowledge base. The following database entries are recognized.
text(<name suffix>, <mime type>):         Library file.
binary(<name suffix >, <mime-type>):    Foreign file.
resource(<name suffix >, <mime-type>):    Resource file.
sys_remove_file_extension(E):
The predicate succeeds in removing file extension database entry with the name suffix E from the current knowledge base.
sys_current_file_extension(E):
The predicate succeeds in E with the currently added file extension database entries along the knowledge bases.
absolute_file_name(R, A):
absolute_file_name(R, A, O):
The binary predicate succeeds when the read path R resolves to an absolute path and this absolute path unifies with S. The ternary predicate additionally recognizes the following path option:
access(M): M is the access (read, write or append).
The binary predicate can also be used in a backward manner.
absolute_resource_name(R, A):
The binary predicate succeeds when the read path R resolves to an absolute resource path A.

The following Prolog flags for path resolution are provided:

base_url:
The legal value is an atom. The value is the base URL of the current knowledge base. A missing base URL is indicated by the atom ‘’. The value can be changed.

Kommentare