emacs.d/clones/lisp/www.cs.cmu.edu/Groups/AI/html/cltl/clm/node218.html

87 lines
4.9 KiB
HTML
Raw Normal View History

2022-08-26 19:11:35 +02:00
<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
<!Converted with LaTeX2HTML 0.6.5 (Tue Nov 15 1994) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
<HEAD>
<TITLE>23.5. Accessing Directories</TITLE>
</HEAD>
<BODY>
<meta name="description" value=" Accessing Directories">
<meta name="keywords" value="clm">
<meta name="resource-type" value="document">
<meta name="distribution" value="global">
<P>
<b>Common Lisp the Language, 2nd Edition</b>
<BR> <HR><A NAME=tex2html4274 HREF="node219.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html4272 HREF="node202.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html4268 HREF="node217.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html4276 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html4277 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME=tex2html4275 HREF="node219.html"> Errors</A>
<B>Up:</B> <A NAME=tex2html4273 HREF="node202.html"> File System Interface</A>
<B> Previous:</B> <A NAME=tex2html4269 HREF="node217.html"> Loading Files</A>
<HR> <P>
<H1><A NAME=SECTION002750000000000000000>23.5. Accessing Directories</A></H1>
<P>
The following function is a very simple portable primitive for examining
a directory. Most file systems can support much more powerful
directory-searching primitives, but no two are alike.
It is expected that most implementations of Common Lisp will extend the
<tt>directory</tt> function or provide more powerful
primitives.
<P>
<BR><b>[Function]</b><BR>
<tt>directory <i>pathname</i> &amp;key</tt><P>A list of pathnames is returned, one for each
file in the file system that matches the given <i>pathname</i>.
(The <i>pathname</i> argument may be a pathname, a string,
or a stream associated with a file.)
For a file that matches, the <tt>truename</tt> appears
in the result list.
If no file matches the <i>pathname</i>, it is not an error;
<tt>directory</tt> simply returns <tt>nil</tt>, the list of no results.
Keywords such as <tt>:wild</tt> and <tt>:newest</tt> may
be used in <i>pathname</i> to indicate the search space.
<P>
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
X3J13 voted in March 1988
(PATHNAME-STREAM) <A NAME=27783>&#160;</A>
to specify exactly which streams may be used as pathnames.
See section <A HREF="node214.html#PATHNAMEFUNCTIONS">23.1.6</A>.
<P>
X3J13 voted in January 1989
(CLOSED-STREAM-OPERATIONS) <A NAME=27787>&#160;</A>
to specify that <tt>directory</tt> is unaffected by
whether the first argument, if a stream, is open or closed. If the first
argument is a stream, <tt>directory</tt> behaves as if the function <tt>pathname</tt>
were applied to the stream and the resulting pathname used instead.
However, X3J13 commented that the treatment of open streams
may differ considerably from one implementation to another; for example,
in some operating systems open files are written under a temporary or
invisible name and later renamed when closed. In general, programmers writing
code intended to be portable should be careful when using <tt>directory</tt>.
<P>
X3J13 voted in June 1989 (PATHNAME-LOGICAL) <A NAME=27794>&#160;</A> to require <tt>directory</tt>
to accept logical pathnames (see section <A HREF="node208.html#LOGICALPATHNAMESSECTION">23.1.5</A>).
However, the result returned by <tt>directory</tt> never contains a logical pathname.
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
<P>
<hr>
<b>Implementation note:</b> It is anticipated that
an implementation may need to provide additional
parameters to control the directory search. Therefore <tt>directory</tt>
is specified to take additional keyword arguments so that implementations
may experiment with extensions,
even though no particular keywords are specified here.
<P>
As a simple example of such an extension, for a file system that
supports the notion of cross-directory file links,
a keyword argument <tt>:links</tt> might, if non-<tt>nil</tt>,
specify that such links be included in the result list.
<hr>
<P>
<BR> <HR><A NAME=tex2html4274 HREF="node219.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html4272 HREF="node202.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html4268 HREF="node217.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html4276 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html4277 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME=tex2html4275 HREF="node219.html"> Errors</A>
<B>Up:</B> <A NAME=tex2html4273 HREF="node202.html"> File System Interface</A>
<B> Previous:</B> <A NAME=tex2html4269 HREF="node217.html"> Loading Files</A>
<HR> <P>
<HR>
<P><ADDRESS>
AI.Repository@cs.cmu.edu
</ADDRESS>
</BODY>