Next Prev Up Top Contents Index

directory

Function
Summary

Determines which files on the system have named matching a given pathname.

Package

common-lisp

Signature

directory pathname &key test directories link-transparency non-existent-link-destinations => pathnames

Arguments

pathname

A pathname, string, or file-stream.

test

Filtering test (only pathnames matching the test are collected).

directories

A boolean controlling whether non-matching directories are included in the result.

link-transparency

If nil , then symbolic links are not followed. This means that returned names are not necessarily truenames, but has the useful feature that the pathname-directory of each pathname returned is the directory supplied as argument.

The default value of link-transparency is given by the special variable, system:*directory-link-transparency* , which is initially non- nil on Unix/Linux. By setting this variable to nil , you can get the old behavior of directory . On Windows, where the file system does not normally support symbolic links, this variable is initially nil .

non-existent-link-destinations

If this is non- nil , then the pathname pointed to by a symbolic link appears in the output whether or not this file actually exists. If :link-transparency is non- nil and :non-existent-link-destinations is nil (this is the default on Unix/Linux), then symbolic links to nonexistent files do not appear.

The default value is nil .

Values

pathnames

A list of physical pathnames.

Description

directory collects all the pathnames matching the given pathname.

directory returns truenames, conforming to the ANSI specification for Common Lisp. Some programs may depend on the old behavior, however (and directory is slower if it has to find the truename for every file in the directory), and so two keyword arguments are available so that the old behavior can still be used: link-transparency and non-existent-link-destinations .

Because truenames are now returned, the entries . and .. no longer show up in the output of directory . This means, for instance, that

(directory #P"/usr/users/")

does not include #P"/usr" , which is the truename of #P"/usr/users/.."

The specification is unclear as to the appropriate behavior of directory in the presence of links to non-existent files or directories. For example, if the directory contains foo , which is a symbolic link to bar , and there is no file named bar , should bar show up in the directory listing? A keyword argument has been added which lets you control this behavior.

directories , if non- nil , causes paths of directories that are sub-directories of the directory of the argument pathname to be included in the result, even if they do not match pathname in the name, type or version components. The default value of directories is nil .

Note: File names containing the character * cannot be handled by LispWorks. This is because LispWorks uses * as a wildcard, so there can be confusion if a file name containing * is created, for example in the pathnames returned by directory .

Compatibility Note

The :check-for-subs argument, implemented in LispWorks 4.0.1 and previous versions, has been removed. This argument controlled whether directories in the result have null name components. This option is no longer valid since ANSI Common Lisp specifies that directory returns truenames.

Example
CL-USER 42 > (pprint (directory "."))
 
(#P"C:/Program Files/Xanalys/LispWorks/ReadMe-4200.txt"
 #P"C:/Program Files/Xanalys/LispWorks/MSVCRT.DLL"
 #P"C:/Program Files/Xanalys/LispWorks/LW4200.isu"
 #P"C:/Program Files/Xanalys/LispWorks/lispworks-4200.exe"
 #P"C:/Program Files/Xanalys/LispWorks/license-4200.txt"
 #P"C:/Program Files/Xanalys/LispWorks/lib/")

This session illustrates the effect of the directories argument:

CL-USER 20 > (directory "/Temp/t*")
(#P"/Temp/test.lisp")
 
CL-USER 21 > (directory "/Temp/t*" :directories t)
(#P"/Temp/test.lisp" #P"/Temp/mozilla cache 1/"
#P"/Temp/test/" #P"/Temp/test2/")

LispWorks Reference Manual - 13 Jun 2003

Next Prev Up Top Contents Index