287 lines
21 KiB
HTML
287 lines
21 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<!-- Created by GNU Texinfo 7.0.3, https://www.gnu.org/software/texinfo/ -->
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<title>Filenames (ECL Manual)</title>
|
|
|
|
<meta name="description" content="Filenames (ECL Manual)">
|
|
<meta name="keywords" content="Filenames (ECL Manual)">
|
|
<meta name="resource-type" content="document">
|
|
<meta name="distribution" content="global">
|
|
<meta name="Generator" content="makeinfo">
|
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
|
|
<link href="index.html" rel="start" title="Top">
|
|
<link href="Indexes.html" rel="index" title="Indexes">
|
|
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
|
|
<link href="Standards.html" rel="up" title="Standards">
|
|
<link href="Files.html#Files" rel="next" title="Files">
|
|
<link href="Hash-tables.html#Hash-tables" rel="prev" title="Hash tables">
|
|
<style type="text/css">
|
|
<!--
|
|
/* colors */
|
|
|
|
span.r {font-family: initial; font-weight: normal; font-style: normal}
|
|
ul.mark-bullet {list-style-type: disc}
|
|
@media (prefers-color-scheme: dark) {
|
|
/* dark theme */
|
|
html { color: seashell;
|
|
background: #1A1A1A; }
|
|
body { background: #1A1A1A; }
|
|
th { border-bottom: 2px solid lightgray; }
|
|
h1, h2, h3, h4, h5 { background-image: linear-gradient(to left, #202020, #3A3A3A); }
|
|
code, var, code a { color: darkorange;
|
|
background: #2A2A2A; }
|
|
a { color: seashell; }
|
|
pre { background: #2A2A2A;
|
|
color: seashell;
|
|
/* mark longer code block with stripe on the left */
|
|
border-left: 5px solid darkorange;
|
|
padding-left: 10px; }
|
|
pre.screen { background: #2A2A2A;
|
|
border: 1px solid lightgray; }
|
|
pre.programlisting { background: #2A2A2A;
|
|
border-left: 1px solid lightgray;
|
|
border-top: 1px solid lightgray; }
|
|
/* we need a light background in order for the images to be readable */
|
|
img { background: white }
|
|
}
|
|
@media (prefers-color-scheme: light) {
|
|
/* light theme */
|
|
html { background: white }
|
|
body { background: white }
|
|
th { border-bottom: 2px solid gray; }
|
|
h1, h2, h3, h4, h5 { background: lightgray; }
|
|
code, var, code a { color: darkred;
|
|
background: whitesmoke; }
|
|
a { color: #000; }
|
|
pre { background: whitesmoke;
|
|
color: black;
|
|
/* mark longer code block with stripe on the left */
|
|
border-left: 5px solid darkred;
|
|
padding-left: 10px; }
|
|
pre.screen { background: #EEE;
|
|
border: 1px solid black; }
|
|
pre.programlisting { background: #EEEEEE;
|
|
border-left: 1px solid black;
|
|
border-top: 1px solid black; }
|
|
}
|
|
|
|
body {
|
|
margin: 1em 125px 0 10%;
|
|
line-height: 1.5em;
|
|
padding: 0 2em 1em 2em;
|
|
font: 13px Verdana,Arial, sans-serif
|
|
}
|
|
ul, dd, dl, dt { margin-top: 0; margin-bottom: 0; }
|
|
p, code, td, dl, dt {
|
|
line-height: 1.5em;
|
|
}
|
|
table {
|
|
font: inherit;
|
|
border-collapse: collapse;
|
|
}
|
|
th, td {
|
|
vertical-align: top;
|
|
}
|
|
h1, h2, h3 { padding-left: 15px; }
|
|
h4, h5 { padding-left: 5px; }
|
|
code, pre {
|
|
font-size: 1em;
|
|
font-family: monospace;
|
|
}
|
|
var {
|
|
font-size: 1em;
|
|
}
|
|
/* links inside code appear the same as the code itself */
|
|
code a {
|
|
font-weight: normal;
|
|
text-decoration: none;
|
|
}
|
|
/* but get an underline when hovering */
|
|
code a:hover {
|
|
text-decoration: underline;
|
|
}
|
|
/* ordinary links appear in bold */
|
|
a { font-weight: bold; }
|
|
pre.verbatim {
|
|
margin: 0 0 0 0;
|
|
}
|
|
pre {
|
|
overflow: auto;
|
|
}
|
|
pre.screen {
|
|
font-weight: bold;
|
|
padding: 0.5em;
|
|
}
|
|
pre.programlisting {
|
|
padding: 0.5em;
|
|
}
|
|
div p { padding: 0 2em }
|
|
li p { padding: 0; margin: 0 }
|
|
hr { display: none; }
|
|
div.funcsynopsis p {
|
|
text-indent: -2em;
|
|
}
|
|
div.variablelist {
|
|
padding: 0 2em;
|
|
}
|
|
.type, .funcsynopsis, .symbol {
|
|
font-family: monospace;
|
|
}
|
|
.type, .symbol, .replaceable {
|
|
white-space: nowrap;
|
|
}
|
|
|
|
-->
|
|
</style>
|
|
|
|
|
|
</head>
|
|
|
|
<body lang="en">
|
|
<div class="section-level-extent" id="Filenames">
|
|
<div class="nav-panel">
|
|
<p>
|
|
Next: <a href="Files.html#Files" accesskey="n" rel="next">Files</a>, Previous: <a href="Hash-tables.html#Hash-tables" accesskey="p" rel="prev">Hash tables</a>, Up: <a href="Standards.html" accesskey="u" rel="up">Standards</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indexes.html" title="Index" rel="index">Index</a>]</p>
|
|
</div>
|
|
<h3 class="section" id="Filenames-1">2.17 Filenames</h3>
|
|
|
|
|
|
<ul class="mini-toc">
|
|
<li><a href="Filenames.html#Filenames-_002d-Syntax" accesskey="1">Syntax</a></li>
|
|
<li><a href="Filenames.html#Filenames-_002d-Wild-pathnames-and-matching" accesskey="2">Wild pathnames and matching</a></li>
|
|
<li><a href="Filenames.html#Filenames-_002d-C-Reference" accesskey="3">C Reference</a></li>
|
|
</ul>
|
|
<hr>
|
|
<div class="subsection-level-extent" id="Filenames-_002d-Syntax">
|
|
<div class="nav-panel">
|
|
<p>
|
|
Next: <a href="Filenames.html#Filenames-_002d-Wild-pathnames-and-matching" accesskey="n" rel="next">Wild pathnames and matching</a>, Up: <a href="Filenames.html#Filenames" accesskey="u" rel="up">Filenames</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indexes.html" title="Index" rel="index">Index</a>]</p>
|
|
</div>
|
|
<h4 class="subsection" id="Syntax">2.17.1 Syntax</h4>
|
|
<p>A pathname in the file system of Common-Lisp consists of six elements: host, device, directory, name, type and version. Pathnames are read and printed using the <code class="code">#P</code> reader macro followed by the namestring. A namestring is a string which represents a pathname. The syntax of namestrings for logical pathnames is well explained in the ANSI [see <a class="pxref" href="Bibliography.html">ANSI</a>] and it can be roughly summarized as follows:
|
|
</p>
|
|
<pre class="verbatim">[hostname:][;][directory-item;]0 or more[name][.type[.version]]
|
|
hostname = word
|
|
directory-item = wildcard-word
|
|
type, name = wildcard-word without dots
|
|
</pre>
|
|
<p>Here, <var class="var">wildcard-word</var> is a sequence of any character excluding <code class="code">#\Null</code> and dots. <var class="var">word</var> is like a <var class="var">wildcard-word</var> but asterisks are excluded.
|
|
</p>
|
|
<p>The way ECL parses a namestring is by first looking for the <var class="var">hostname</var> component in the previous template. If it is found and it corresponds to a previously defined logical hostname, it assumes that the namestring corresponds to a logical pathname. If <var class="var">hostname</var> is not found or it is not a logical hostname, then ECL tries the physical pathname syntax
|
|
</p>
|
|
<pre class="verbatim">[device:][[//hostname]/][directory-item/]0 or more[name][.type]
|
|
device, hostname = word
|
|
directory-item = wildcard-word
|
|
type = wildcard-word without dots
|
|
name = [.]wildcard-word
|
|
</pre>
|
|
<p>If this syntax also fails, then the namestring is not a valid pathname string and a <code class="code">parse-error</code> will be signaled.
|
|
</p>
|
|
<p>It is important to remark that in ECL, all physical namestrings result into pathnames with a version equal to <code class="code">:newest</code>. Pathnames which are not logical and have any other version (i. e. <code class="code">nil</code> or a number), cannot be printed readably, but can produce a valid namestring which results of ignoring the version.
|
|
</p>
|
|
<p>Finally, an important rule applies to physical namestrings: if a namestring contains one or more periods ‘.’, the last period separates the namestring into the file name and the filetype. However, a namestring with a single leading period results in a name with a period in it. This is for compatibility with Unix filenames such as <code class="code">.bashrc</code>, where the leading period indicates that the file is hidden.
|
|
</p>
|
|
<p>The previous rule has in important consequence, because it means that if you want to create a pathname without a name, you have to do it explicitely. In other words, <code class="code">".*"</code> is equivalent to <code class="code">(make-pathname :name ".*" :type nil)</code>, while <code class="code">(make-pathname :name nil :type :wild)</code> creates a pathname whose type is a wildcard.
|
|
</p>
|
|
<p>The following table illustrates how the physical pathnames work with practical examples.
|
|
</p>
|
|
<div class="float" id="tab_003aexample_002dphysical_002dnamestrings">
|
|
|
|
<table class="multitable">
|
|
<thead><tr><th width="28%">Namestring</th><th width="12%">Name</th><th width="10%">Type</th><th width="30%">Directory</th><th width="20%">Device</th></tr></thead>
|
|
<tbody><tr><td width="28%"><code class="code">"foo.lsp"</code></td><td width="12%"><code class="code">"foo"</code></td><td width="10%"><code class="code">"lsp"</code></td><td width="30%"><code class="code">nil</code></td><td width="20%"><code class="code">nil</code></td></tr>
|
|
<tr><td width="28%"><code class="code">".bashrc"</code></td><td width="12%"><code class="code">".bashrc"</code></td><td width="10%"><code class="code">nil</code></td><td width="30%"><code class="code">nil</code></td><td width="20%"><code class="code">nil</code></td></tr>
|
|
<tr><td width="28%"><code class="code">".ecl.lsp"</code></td><td width="12%"><code class="code">".ecl"</code></td><td width="10%"><code class="code">"lsp"</code></td><td width="30%"><code class="code">nil</code></td><td width="20%"><code class="code">nil</code></td></tr>
|
|
<tr><td width="28%"><code class="code">"foo.*"</code></td><td width="12%"><code class="code">"foo"</code></td><td width="10%"><code class="code">:wild</code></td><td width="30%"><code class="code">nil</code></td><td width="20%"><code class="code">nil</code></td></tr>
|
|
<tr><td width="28%"><code class="code">"*.*"</code></td><td width="12%"><code class="code">:wild</code></td><td width="10%"><code class="code">:wild</code></td><td width="30%"><code class="code">nil</code></td><td width="20%"><code class="code">nil</code></td></tr>
|
|
<tr><td width="28%"><code class="code">"ecl/build/bare.lsp"</code></td><td width="12%"><code class="code">"bare"</code></td><td width="10%"><code class="code">"lsp"</code></td><td width="30%"><code class="code">(:relative "ecl" "build")</code></td><td width="20%"><code class="code">nil</code></td></tr>
|
|
<tr><td width="28%"><code class="code">"ecl/build/"</code></td><td width="12%"><code class="code">nil</code></td><td width="10%"><code class="code">nil</code></td><td width="30%"><code class="code">(:relative "ecl" "build")</code></td><td width="20%"><code class="code">nil</code></td></tr>
|
|
<tr><td width="28%"><code class="code">"../../ecl/build/"</code></td><td width="12%"><code class="code">nil</code></td><td width="10%"><code class="code">nil</code></td><td width="30%"><code class="code">(:relative :up :up "ecl" "build")</code></td><td width="20%"><code class="code">nil</code></td></tr>
|
|
<tr><td width="28%"><code class="code">"/etc/"</code></td><td width="12%"><code class="code">nil</code></td><td width="10%"><code class="code">nil</code></td><td width="30%"><code class="code">(:absolute "etc")</code></td><td width="20%"><code class="code">nil</code></td></tr>
|
|
<tr><td width="28%"><code class="code">"C:/etc/"</code></td><td width="12%"><code class="code">nil</code></td><td width="10%"><code class="code">nil</code></td><td width="30%"><code class="code">(:absolute "etc")</code></td><td width="20%"><code class="code">"C"</code></td></tr>
|
|
<tr><td width="28%"><code class="code">".*"</code></td><td width="12%"><code class="code">".*"</code></td><td width="10%"><code class="code">nil</code></td><td width="30%"><code class="code">nil</code></td><td width="20%"><code class="code">nil</code></td></tr>
|
|
<tr><td width="28%"><code class="code">#.(make-pathname :type "*")</code></td><td width="12%"><code class="code">nil</code></td><td width="10%"><code class="code">:wild</code></td><td width="30%"><code class="code">nil</code></td><td width="20%"><code class="code">nil</code></td></tr>
|
|
</tbody>
|
|
</table>
|
|
<div class="caption"><p><strong class="strong">Table 2.8: </strong>Examples of physical namestrings</p></div></div>
|
|
<hr>
|
|
</div>
|
|
<div class="subsection-level-extent" id="Filenames-_002d-Wild-pathnames-and-matching">
|
|
<div class="nav-panel">
|
|
<p>
|
|
Next: <a href="Filenames.html#Filenames-_002d-C-Reference" accesskey="n" rel="next">C Reference</a>, Previous: <a href="Filenames.html#Filenames-_002d-Syntax" accesskey="p" rel="prev">Syntax</a>, Up: <a href="Filenames.html#Filenames" accesskey="u" rel="up">Filenames</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indexes.html" title="Index" rel="index">Index</a>]</p>
|
|
</div>
|
|
<h4 class="subsection" id="Wild-pathnames-and-matching">2.17.2 Wild pathnames and matching</h4>
|
|
<p>ECL accepts four kind of wildcards in pathnames.
|
|
</p>
|
|
<ul class="itemize mark-bullet">
|
|
<li>A single wildcard in a directory component, file name, type or version is parsed as the <code class="code">:wild</code> value. See for instance "<code class="code">*.*</code>", "<code class="code">/home/*/.bashrc</code>", etc
|
|
|
|
</li><li>A double wildcard in a directory component, such as in "<code class="code">/home/**/</code>" is parsed as the <code class="code">:wild-inferiors</code>, and matches any number of directories, even nested ones, such as: <code class="code">/home/</code>, <code class="code">/home/jlr</code>, <code class="code">/home/jlr/lib</code>, etc.
|
|
|
|
</li><li>An isolated wildcard "<code class="code">log*.txt</code>" matches any number of characters: <code class="code">log.txt</code>, <code class="code">log_back.txt</code>, etc.
|
|
|
|
</li><li>A question mark "<code class="code">log?.txt</code>" matches a single character: <code class="code">log1.txt</code>, <code class="code">log2.txt</code>...
|
|
</li></ul>
|
|
|
|
<p>The matching rules in Common Lisp and ECL are simple but have some unintuitive consequences when compared to Unix/DOS rules. The most important one is that directories must always end with a trailing slash <code class="code">/</code>, as in <code class="code">#p"/my/home/directory/"</code>. Second to that, <code class="code">nil</code> values can only be matched by <code class="code">nil</code> and <code class="code">:wild</code>. Hence, "<code class="code">*</code>" can only match files without file type. For some examples see <a class="ref" href="Files.html#Files-_002d-Dictionary">Dictionary</a>.
|
|
</p>
|
|
<hr>
|
|
</div>
|
|
<div class="subsection-level-extent" id="Filenames-_002d-C-Reference">
|
|
<div class="nav-panel">
|
|
<p>
|
|
Previous: <a href="Filenames.html#Filenames-_002d-Wild-pathnames-and-matching" accesskey="p" rel="prev">Wild pathnames and matching</a>, Up: <a href="Filenames.html#Filenames" accesskey="u" rel="up">Filenames</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indexes.html" title="Index" rel="index">Index</a>]</p>
|
|
</div>
|
|
<h4 class="subsection" id="C-Reference-16">2.17.3 C Reference</h4>
|
|
|
|
<ul class="mini-toc">
|
|
<li><a href="Filenames.html#ANSI-dictionary-5" accesskey="1">ANSI dictionary</a></li>
|
|
</ul>
|
|
<div class="subsubsection-level-extent" id="ANSI-dictionary-5">
|
|
<h4 class="subsubsection">2.17.3.1 ANSI dictionary</h4>
|
|
<p>Common Lisp and C equivalence
|
|
</p>
|
|
<table class="multitable">
|
|
<thead><tr><th width="30%">Lisp symbol</th><th width="70%">C function</th></tr></thead>
|
|
<tbody><tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_namest.htm">directory-namestring</a></td><td width="70%">cl_object cl_directory_namestring(cl_object pathname)</td></tr>
|
|
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_namest.htm">enough-namestring</a></td><td width="70%">cl_object cl_enough_namestring(cl_narg narg, cl_object pathname, ...)</td></tr>
|
|
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_namest.htm">file-namestring</a></td><td width="70%">cl_object cl_file_namestring(cl_object pathname)</td></tr>
|
|
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_namest.htm">host-namestring</a></td><td width="70%">cl_object cl_host_namestring(cl_object pathname)</td></tr>
|
|
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_ld_log.htm">load-logical-pathname-translations</a></td><td width="70%">cl_object cl_load_logical_pathname_translations(cl_object host)</td></tr>
|
|
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_logica.htm">logical-pathname-translations</a></td><td width="70%">cl_object cl_logical_pathname_translations(cl_object host)</td></tr>
|
|
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_logi_1.htm">logical-pathname</a></td><td width="70%">cl_object cl_logical_pathname(cl_object pathspec)</td></tr>
|
|
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_pn.htm">make-pathname</a></td><td width="70%">cl_object cl_make_pathname(cl_narg narg, ...)</td></tr>
|
|
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_merge_.htm">merge-pathnames</a></td><td width="70%">cl_object cl_merge_pathnames(cl_narg narg, cl_object pathname,...)</td></tr>
|
|
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_namest.htm">namestring</a></td><td width="70%">cl_object cl_namestring(cl_object pathname)</td></tr>
|
|
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_pars_1.htm">parse-namestring</a></td><td width="70%">cl_object cl_parse_namestring(cl_narg narg, cl_object thing, ...)</td></tr>
|
|
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/pathname.htm">pathname</a></td><td width="70%">cl_object cl_pathname(cl_object pathspec)</td></tr>
|
|
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_pn_hos.htm">pathname-device</a></td><td width="70%">cl_object cl_pathname_device(cl_narg narg, cl_object pathname, ...)</td></tr>
|
|
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_pn_hos.htm">pathname-directory</a></td><td width="70%">cl_object cl_pathname_directory(cl_narg narg, cl_object pathname, ...)</td></tr>
|
|
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_pn_hos.htm">pathname-host</a></td><td width="70%">cl_object cl_pathname_host(cl_narg narg, cl_object pathname, ...)</td></tr>
|
|
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_pn_mat.htm">pathname-match-p</a></td><td width="70%">cl_object cl_pathname_match_p(cl_object pathname, cl_object wildcard)</td></tr>
|
|
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_pn_hos.htm">pathname-name</a></td><td width="70%">cl_object cl_pathname_name(cl_narg narg, cl_object pathname, ...)</td></tr>
|
|
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_pn_hos.htm">pathname-type</a></td><td width="70%">cl_object cl_pathname_type(cl_narg narg, cl_object pathname, ...)</td></tr>
|
|
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_pn_hos.htm">pathname-version</a></td><td width="70%">cl_object cl_pathname_version(cl_object pathname)</td></tr>
|
|
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_pnp.htm">pathnamep</a></td><td width="70%">cl_object cl_pathnamep(cl_object object)</td></tr>
|
|
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_tr_log.htm">translate-logical-pathname</a></td><td width="70%">cl_object cl_translate_logical_pathname(cl_narg narg, cl_object pathname, ...)</td></tr>
|
|
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_tr_pn.htm">translate-pathname</a></td><td width="70%">cl_object cl_translate_pathname(cl_narg narg, cl_object source, cl_object from_wildcard, cl_object to_wildcard, ...)</td></tr>
|
|
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_wild_p.htm">wild-pathname-p</a></td><td width="70%">cl_object cl_wild_pathname_p(cl_narg narg, cl_object pathname, ...)</td></tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<hr>
|
|
<div class="nav-panel">
|
|
<p>
|
|
Next: <a href="Files.html#Files" accesskey="n" rel="next">Files</a>, Previous: <a href="Hash-tables.html#Hash-tables" accesskey="p" rel="prev">Hash tables</a>, Up: <a href="Standards.html" accesskey="u" rel="up">Standards</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indexes.html" title="Index" rel="index">Index</a>]</p>
|
|
</div>
|
|
|
|
|
|
|
|
</body>
|
|
</html>
|