CL-FAD - A portable pathname library for Common Lisp


 

Abstract

CL-FAD (for "Files and Directories") is a thin layer atop Common Lisp's standard pathname functions. It is intended to provide some unification between current CL implementations on Windows, OS X, Linux, and Unix. Most of the code was written by Peter Seibel for his book Practical Common Lisp.

CL-FAD comes with a BSD-style license so you can basically do with it whatever you want.


 

Contents

  1. Download and installation
  2. Supported Lisp implementations
  3. The CL-FAD dictionary
    1. directory-pathname-p
    2. pathname-as-directory
    3. pathname-as-file
    4. file-exists-p
    5. directory-exists-p
    6. list-directory
    7. walk-directory
    8. delete-directory-and-files
    9. copy-file
  4. Acknowledgements

 

Download and installation

CL-FAD together with this documentation can be downloaded from http://weitz.de/files/cl-fad.tar.gz. The current version is 0.3.2.

CL-FAD comes with simple system definitions for MK:DEFSYSTEM and asdf so you can either adapt it to your needs or just unpack the archive and from within the CL-FAD directory start your Lisp image and evaluate the form (mk:compile-system "cl-fad") - or (asdf:oos 'asdf:load-op :cl-fad) for asdf - which should compile and load the whole system. Installation via asdf-install should as well be possible. Plus, there are ports for Gentoo Linux thanks to Matthew Kennedy and for Debian Linux thanks to René van Bevern.

If for some reason you can't or don't want to use MK:DEFSYSTEM or asdf you can just LOAD the file load.lisp.
 

Supported Lisp implementations

The following Common Lisp implementations are currently supported:

I'll gladly accepts patches to make CL-FAD work on other platforms.
 

The CL-FAD dictionary


[Function]
directory-pathname-p pathspec => generalized-boolean


Returns NIL if pathspec (a pathname designator) does not designate a directory, pathspec otherwise. It is irrelevant whether the file or directory designated by pathspec does actually exist.


[Function]
pathname-as-directory pathspec => pathname


Converts the non-wild pathname designator pathspec to directory form, i.e. it returns a pathname which would return a true value if fed to DIRECTORY-PATHNAME-P.


[Function]
pathname-as-file pathspec => pathname


Converts the non-wild pathname designator pathspec to file form, i.e. it returns a pathname which would return a NIL value if fed to DIRECTORY-PATHNAME-P.


[Function]
file-exists-p pathspec => generalized-boolean


Checks whether the file named by the pathname designator pathspec exists and returns its truename if this is the case, NIL otherwise. The truename is returned in "canonical" form, i.e. the truename of a directory is returned in directory form as if by PATHNAME-AS-DIRECTORY.


[Function]
directory-exists-p pathspec => generalized-boolean


Checks whether the file named by the pathname designator pathspec exists and if it is a directory. Returns its truename if this is the case, NIL otherwise. The truename is returned in directory form as if by PATHNAME-AS-DIRECTORY.


[Function]
list-directory dirname => list


Returns a fresh list of pathnames corresponding to the truenames of all files within the directory named by the non-wild pathname designator dirname. The pathnames of sub-directories are returned in directory form - see PATHNAME-AS-DIRECTORY.


[Function]
walk-directory dirname fn &key directories if-does-not-exist test => |


Recursively applies the function designated by the function designator fn to all files within the directory named by the non-wild pathname designator dirname and all of its sub-directories. fn will only be applied to files for which the function test returns a true value. (The default value for test always returns true.) If directories is true (the default is NIL), fn and test are applied to directories as well, and fn is guaranteed to be applied to the directory's contents first. if-does-not-exist must be one of :ERROR or :IGNORE where :ERROR (the default) means that an error will be signaled if the directory dirname does not exist.


[Function]
delete-directory-and-files dirname&key if-does-not-exist => |


Recursively deletes all files and directories within the directory designated by the non-wild pathname designator dirname including dirname itself. if-does-not-exist must be one of :ERROR or :IGNORE where :ERROR (the default) means that an error will be signaled if the directory dirname does not exist.


[Function]
copy-file from to &key overwrite => |


Copies the file designated by the non-wild pathname designator from to the file designated by the non-wild pathname designator to. If overwrite is true (the default is NIL) overwrites the file designtated by to if it exists.

 

Acknowledgements

The original code for this library was written by Peter Seibel for his book Practical Common Lisp. I added some stuff and made sure it worked properly on Windows, specifically with CCL. Thanks to Maciek Pasternacki and Jack D. Unrue who sent patches for ECL and ABCL.

$Header$

BACK TO MY HOMEPAGE