Introduction -- library(directory)

For the most part, Prolog programs have little need to examine directories or to inquire about file properties. However, the need does occasionally arise. For example, an expert-system shell might offer the option of either loading a single file into its knowledge base, or of loading all the files in a directory having a particular extension. The Quintus Prolog library file library(directory) provides the tools you need to do this. For example, we might define

     kb_load(File) :-
         (  directory_property(File, searchable) ->
               forall(file_member_of_directory(File,'*.kb',_,Full),
                        kb_load(Full))
         ;  file_property(File, readable) ->
               kb_load_file(File)
         ;  format(user_error, '~N! cannot read ~w.~n', [File]),
            fail
         ).
     

The routines in this package were designed to be a complete toolkit for safely wandering around a UNIX-like file system. Although there are quite a few of them, they do actually fit together in a coherent group. For information on operations relating to individual files rather than to directories, see library(files) (lib-ofi).

The following principles have been observed: