A directory object is a wrapper around a directory on the computers file-system. XPCE defines behaviour to handle files and directories for two reasons. First of all to support some of its own facilities such as saving things to file or loading things from file. Secondly to allow the user to query the file-system. Normally the host provides similar facilities, but notably for Prolog, not much of a standard exists. Using XPCE's primitives will make this part of your program better portable.
<-base_name.
directory<-path
contains the full path name.-name to
this directory. It is computed from the name argument when the directory
is created. See also
file<-absolute_path.
->exists.
<-path.
->make.
A typical sequence to ensure the existence of a directory is:
... new(D, directory(Path)), ( send(D, exists) -> true ; send(D, make) ), ...
See also directory->access.
~ or ~<user>
is expanded as are shell variables notated as $<name>. directory<-path
is filled with an absolute path to this directory, directory<-name
with the basename of the directory.
->remove
and
directory->exists.->modified.
The first call just writes the current modification time in -modified
and fails. If the directory does not exist any longer, directory->modified
succeeds as well.
This method is intended for periodic changes to the set of members in
a visualised directory. See also file<-time.
->push
to temporary switch directories.
->cd.
When successful, the old working directory is prepended to the chain @directory_stack
as a name. The method directory->pop
allows you to go back to the original directory.
->make
and directory->exists.->same.If the same chain is given for files and directories, directory->scan
will not determine the type. Depending on your Unix version, this may be much
faster.
Bugs: Changes working directory while running. This will not be undone when execution is aborted while scanning the directory.
->initialise
for details.
The names in the chain are alphabetically ordered.
name starts with a’/’or’~’,
these methods just return a new file or directory from name.
Otherwise the new object will be created from directory<-path,
and name, separated with a’/’.name denotes an
absolute path it is returned unmodified. See also directory<-file,
directory<-directory
and directory<-parent.pwd on the entry _.._ and
the second is to strip of the last part of the path by scanning for a’/’.
XPCE uses the latter approach.
directory<-parent
fails silently if the directory refers to the root of the file-system.
<-roots
gathers the roots of the filesystem. On Unix, there is only one root, so
a chain holding only’/’is returned. On windows, it returns
the path-names of all defined logical drives. This call is used by library(find_file)
to show all defined drives after an up from a drive-root.
The content of the directory object itself is not examined. For example (Windows):
?- get(directory('.'), roots, Roots),
chain_list(Roots, List).
List = ['a:/', 'c:/', 'd:/', 'e:/', 's:/']