Lpp provides a small collection of file system interface functions
that are somewhat similar to corresponding Common Lisp functions.
Since C++ provides a library of file stream functions these Lpp file
system interface functions are not absolutely necessary. They do
however make it easy to bring the file system into Lisp semantics.
For example the fileDirectory function returns a Lisp list of
file names.
| currentDirectory | Function |
currentDirectory returns an Lpp String that represents the
environment's notion of the current directory that the Lpp
program is executing in. For example in Unix this is the current
directory when main was executed. The returned String has a
terminating directory identifier (if such exists) such that if the
String were concatenated with a plain file name the result would be a
complete file specification. For example suppose on a Unix system the
current directory is /home/me/lpp/lib then
stringConcat(currentDirectory(), L("filex"))
=> "/home/me/lpp/lib/filex"
| fileDirectory file | Function |
Given a file specification file fileDirectory will
return a list of names of the files in the directory if the given
specification names a directory in the file system or a file
specification relative to the current directory. An error is
signaled if the the given file can not be opened as a
directory. The file argument can be an Lpp String or a
char* string. The returned list of names are Lpp Strings.
Here are some examples
let dirList = fileDirectory(currentDirectory());
int dirLength = length(fileDirectory("/home/me/lpp/lib/test"));
let filtered = mapcan(L(filterFunction), fileDirectory("test"));
Note that fileDirectory is similar to the directory
function in Common Lisp. But while the argument to directory
is a file pattern string in Common Lisp the argument to
fileDirectory is an exact directory name.
| probeFile file pred | Function |
Given a file specification file and a predicate symbol
pred returns t if what pred indicates is true of
the given file and nil otherwise. The argument
file is a file specification in the file system or a
specification relative to the current directory. It can be a
char* string or an Lpp String. The pred argument can be
one of the symbols: exist, readable, writable,
executable, directory, regular,
symbolicLink.
If given the symbol exist probeFile returns t if
the given file specification exists. If give readable,
writable or executable it will return t if the
file is readable, writable or executable respectively. If given
directory it returns true if the file specification is a
directory. If given regular it will return t if the file
is a regular file. Note that a regular file can be other than a
non-directory in some file systems, such as a Unix file system. For
file systems that have symbolic links, if given the symbol
symbolicLink it returns t if the file is a symbolic
link.
For example the directory symbol can be used to recursively
descend directories
void recursiveDescend(let directory) {
dolist(file, fileDirectory(directory)) {
// Do something with this file.
if (probeFile(file, S(directory))) recursiveDescend(file);}}
Note that calling probeFile with the symbol exist is
similar to the probe-file of Common Lisp, that is, it is a
predicate for the existence of the file. But where probe-file
in Common Lisp returns the true name of the file probeFile just
returns t if the file exists. This was done on purpose in Lpp
to avoid generating a String object that would just need to be garbage
collected if all that we wanted to use probeFile for was as a
predicate.