cl-fad

API Reference

cl-fad

Portable pathname library

CL-FAD

  • Function DIRECTORY-PATHNAME-P (pathspec)
    Returns NIL if PATHSPEC (a pathname designator) does not designate a directory, PATHSPEC otherwise. It is irrelevant whether file or directory designated by PATHSPEC does actually exist.
  • Function PATHNAME-AS-DIRECTORY (pathspec)
    Converts the non-wild pathname designator PATHSPEC to directory form.
  • Function LIST-DIRECTORY (dirname &key (follow-symlinks t))
    Returns a fresh list of pathnames corresponding to 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. If FOLLOW-SYMLINKS is true, then the returned list contains truenames (symlinks will be resolved) which essentially means that it might also return files from *outside* the directory. This works on all platforms. When FOLLOW-SYMLINKS is NIL, it should return the actual directory contents, which might include symlinks. Currently this works on SBCL and CCL.
  • Function PATHNAME-AS-FILE (pathspec)
    Converts the non-wild pathname designator PATHSPEC to file form.
  • Function FILE-EXISTS-P (pathspec)
    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 as if by PATHNAME-AS-DIRECTORY.
  • Function DIRECTORY-EXISTS-P (pathspec)
    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 WALK-DIRECTORY (dirname fn &key directories (if-does-not-exist :error) (test (constantly t)) (follow-symlinks t))
    Recursively applies the function 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. If DIRECTORIES is not NIL, FN and TEST are applied to directories as well. If DIRECTORIES is :DEPTH-FIRST, FN will be applied to the directory's contents first. If DIRECTORIES is :BREADTH-FIRST and TEST returns NIL, the directory's content will be skipped. IF-DOES-NOT-EXIST must be one of :ERROR or :IGNORE where :ERROR means that an error will be signaled if the directory DIRNAME does not exist. If FOLLOW-SYMLINKS is T, then your callback will receive truenames. Otherwise you should get the actual directory contents, which might include symlinks. This might not be supported on all platforms. See LIST-DIRECTORY.
  • Function COPY-STREAM (from to &optional (checkp t))
    Copies into TO (a stream) from FROM (also a stream) until the end of FROM is reached, in blocks of *stream-buffer-size*. The streams should have the same element type. If CHECKP is true, the streams are checked for compatibility of their types.
  • 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 overwrites the file designated by TO if it exists.
  • Function DELETE-DIRECTORY-AND-FILES (dirname &key (if-does-not-exist :error))
    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 means that an error will be signaled if the directory DIRNAME does not exist. NOTE: this function is dangerous if the directory that you are removing contains symlinks to files outside of it - the target files might be removed instead! This is currently fixed for SBCL and CCL.
  • Function PATHNAME-DIRECTORY-PATHNAME (pathname)
    Returns a complete pathname representing the directory of PATHNAME. If PATHNAME is already a directory pathname (name NIL, type NIL) returns a pathname equal (as per pathname=) to it.
  • Function PATHNAME-PARENT-DIRECTORY (pathname)
    Returns a pathname which would, by name at least, contain PATHNAME as one of its direct children. Symlinks can make the parent/child relationship a like opaque, but generally speaking the value returned by this function is a directory name which contains PATHNAME. The root directory, #P"/", is its own parent. The parent directory of a filename is the parent of the filename's dirname.
  • Function CANONICAL-PATHNAME (pathname)
    Remove redundant information from PATHNAME. This simply walks down PATHNAME's pathname-directory and drops "." directories, removes :back and its preceding element. NB: This function does not access the filesystem, it only looks at the values in the pathname and works on their known (or assumed) meanings. NB: Since this function does not access the filesystem it will only remove :BACK elements from the path (not :UP elements). Since some lisps, ccl/sbcl/clisp convert ".." in pathnames to :UP, and not :BACK, the actual utility of the function is limited.
  • Function MERGE-PATHNAMES-AS-DIRECTORY (&rest pathnames)
    Given a list of (probably relative) pathnames, this returns a single directory pathname containing the logical concatenation of them all. The returned value is the current directory if one were to cd into each of PATHNAMES in order. For this reason an absolute pathname will, effectively, cancel the affect of any previous relative pathnames. The returned value's defaults are taken from the first element of PATHNAMES (host, version and device). NB: Since this function only looks at directory names the name and type of the elements of PATHNAMES are ignored. Make sure to properly use either trailing #\/s, or pathname-as-directory, to get the expected results. Examples: (merge-pathnames-as-directory #P"foo/" #P"bar/") == #P"foo/bar/" (merge-pathnames-as-directory #P"foo/" #P"./bar/") == #P"foo/./bar/" (merge-pathnames-as-directory #P"foo/" #P"/bar/") == #P"/bar/" (merge-pathnames-as-directory #P"foo/" #P"/bar/" #P"quux/file.txt") == #P"/bar/quux/"
  • Function MERGE-PATHNAMES-AS-FILE (&rest pathnames)
    Given a list of, probably relative, pathnames returns a single filename pathname containing the logical concatenation of them all. The returned value's defaults are taken from the first element of PATHNAMES (host, version and device). The returned values's name, type and version are taken from the last element of PATHNAMES. The intervening elements are used only for their pathname-directory values. Examples: (merge-pathnames-as-file #P"foo/" #P"bar.txt") == #P"foo/bar.txt" (merge-pathnames-as-file #P"foo/" #P"./bar.txt") == #P"foo/./bar.txt" (merge-pathnames-as-file #P"foo/" #P"/bar/README") == #P"/bar/README" (merge-pathnames-as-file #P"/foo/" #P"/bar/" #P"quux/file.txt") == #P"/bar/quux/file.txt"
  • Function PATHNAME-EQUAL (a b)
    Returns T if A and B represent the same pathname. This function does not access the filesystem, it only looks at the components of the two pathnames to test if they are the same (though by passing both A and B to probe-file one can make this function test for file 'sameness'. Equality is defined as: - strings that are string equal - symbol (including nil) or keywords which are eql - lists of the same length with equal (as per these rules) elements. if any of these tree conditions is false for any of the components in A and B then A and B are different, otherwise they are the same. NB: This function does not convert name strings to pathnames. So "foo.txt" and #P"foo.txt" are different pathnames.
  • Function PATHNAME-ABSOLUTE-P (a)
    Returns true if A is an absolute pathname. This simply tests if A's directory list starts with :ABSOLUTE
  • Function PATHNAME-RELATIVE-P (a)
    Returns true if A is a relative pathname. This simply tests if A's directory starts with :RELATIVE.
  • Function PATHNAME-ROOT-P (a)
  • Variable *DEFAULT-TEMPLATE*
    "temporary-files:temp-%"
  • Condition INVALID-TEMPORARY-PATHNAME-TEMPLATE  (ERROR)
  • Condition CANNOT-CREATE-TEMPORARY-FILE  (ERROR)
  • Function OPEN-TEMPORARY (&rest open-arguments &key (template *default-template*) (generate-random-string 'generate-random-string) (max-tries *max-tries*) (direction :output) &allow-other-keys)
    Create a file with a randomly generated name and return the opened stream. The resulting pathname is generated from TEMPLATE, which is a string representing a pathname template. A percent sign (%) in that string is replaced by a randomly generated string to make the filename unique. The default for TEMPLATE places temporary files in the TEMPORARY-FILES logical pathname host, which is automatically set up in a system specific manner. The file name generated from TEMPLATE is merged with *DEFAULT-PATHNAME-DEFAULTS*, so random pathnames relative to that directory can be generated by not specifying a directory in TEMPLATE. GENERATE-RANDOM-STRING can be passed to override the default function that generates the random name component. It should return a random string consisting of characters that are permitted in a pathname (logical or physical, depending on TEMPLATE). The name of the temporary file can be accessed calling the PATHNAME function on STREAM. For convenience, the temporary file is opened on the physical pathname, i.e. if the TEMPLATE designate a logical pathname the translation to a physical pathname is performed before opening the stream. In order to create a unique file name, OPEN-TEMPORARY may loop internally up to MAX-TRIES times before giving up and signalling a CANNOT-CREATE-TEMPORARY-FILE condition.
  • Macro WITH-OUTPUT-TO-TEMPORARY-FILE ((stream &rest args) &body body)
    Create a temporary file using OPEN-TEMPORARY with ARGS and run BODY with STREAM bound to the temporary file stream. Returns the pathname of the file that has been created. See OPEN-TEMPORARY for permitted options.
  • Macro WITH-OPEN-TEMPORARY-FILE ((stream &rest args &key keep &allow-other-keys) &body body)
    Create a temporary file using OPEN-TEMPORARY with ARGS and run BODY with STREAM bound to the temporary file stream. Returns the values returned by BODY. By default, the file is deleted when BODY is exited. If a true value is passed in KEEP, the file is not deleted when the body is exited. See OPEN-TEMPORARY for more permitted options.

PATH

Rexporting certain functions from the cl-fad package with shorter names.

This package provides no functionality, it serves only to make file
system intensive code easier to read (for unix people at least).
  • Function DIRNAME (pathname)
  • Function BASENAME (pathname)
  • Function -E (pathname)
  • Function -D (directory)
  • Function CATFILE (&rest pathnames)
  • Function CATDIR (&rest pathnames)
  • Function = (a b)
  • Function ABSOLUTE-P (pathname)
  • Function RELATIVE-P (pathname)
  • Function ROOT-P (pathname)
  • Function RM-R (pathname)