Next: , Previous: Environment, Up: Osicat


1.3 Directories

— Function: current-directory

current-directory returns the operating system's current directory, which may or may not correspond to *default-pathname-defaults*.

setf current-directory changes the operating system's current directory to the pathspec. An error is signalled if the pathspec is wild or does not designate a directory.

— 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 means that an error will be signaled if the directory dirname does not exist.

— Function: delete-directory pathspec

Deletes the directory designated by pathspec. Returns t. The directory must be empty. Symbolic links are not followed.

Signals an error if pathspec is wild, doesn't designate a directory, or if the directory could not be deleted.

— Function: directory-exists-p pathspec

Checks whether the file named by the pathname designator pathspec exists and is a directory. Returns its truename if this is the case, nil otherwise. Follows symbolic links.

— Function: list-directory pathspec &key bare-pathnames

Returns a fresh list of pathnames corresponding to all files within the directory named by the non-wild pathname designator pathspec. If bare-pathnames is non-NIL only the files's bare pathnames are returned (with an empty directory component), otherwise the files' pathnames are merged with pathspec.

— Function: mapdir function pathspec

Applies function to each entry in directory designated by pathspec in turn and returns a list of the results. Binds *default-pathname-defaults* to the directory designated by pathspec round to function call.

If pathspec designates a symbolic link, it is implicitly resolved.

Signals an error if pathspec is wild or doesn't designate a directory.

— Function: walk-directory dirname fn &key directories if-does-not-exist test

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. Returns t on success.

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.

— Macro: with-directory-iterator (iterator pathspec) &body body

pathspec must be a valid directory designator: *default-pathname-defaults* is bound, and (CURRENT-DIRECTORY) is set to the designated directory for the dynamic scope of the body.

Within the lexical scope of the body, iterator is defined via macrolet such that successive invocations of (ITERATOR) return the directory entries, one by one. Both files and directories are returned, except '.' and '..'. The order of entries is not guaranteed. The entries are returned as relative pathnames against the designated directory. Entries that are symbolic links are not resolved, but links that point to directories are interpreted as directory designators. Once all entries have been returned, further invocations of (ITERATOR) will all return nil.

The value returned is the value of the last form evaluated in body. Signals an error if pathspec is wild or does not designate a directory.