ECL provides a #
macro #P"
that reads a pathname:
#P"
string"
is equivalent to (pathname "
string"
). For
example, #P"foo.lsp"
is equivalent to (pathname "foo.lsp")
.
The same format is used when a pathname is printed.
The initial value of the Common-Lisp variable
*default-pathname-defaults* is #P""
(or, equivalently,
(pathname "")
).
A pathname in the file system of Common-Lisp consists of six elements: host, device, directory, name, type and version.
Let me briefly explain how ECL converts a namestring into a pathname. First ECL tries parsing the namestring using the logical pathnames syntax, which is as follows
[hostname:][;][directory-item;]*[name][.type[.version]] hostname = word directory-item = wildcard-word type, name = wildcard-word without dots version = NEWEST, newest or a numberHere, word is a sequence of one or more characters excluding the
#\Null
character and the asterisk `*'. And
wildcard-word is a sequence of any character excluding
#\Null
and consecutive asterisks (i.e. "**"
is not
allowed).
If hostname is not found or it is not a logical hostname, then ECL tries the physical pathname syntax,
[device:][[//hostname]/][directory-item/]*[name][.type] device, hostname = word directory-item, type = wildcard-word name = a wildcard-word with maybe a single leading dotIf this syntax also fails, then the namestring is not a valid pathname string.
It is important to remark that in ECL, all physical namestrings result into
pathnames with a version equal to :NEWEST
. Pathnames which are not
logical and have any other version (i. e. NIL
or a number), cannot
be printed readably, but can produce a valid namestring which results of
ignoring the version.
The following rules apply to both physical and logical namestrings. First, if a namestring contains one or more periods `.', the last period separates the namestring into the file name and the filetype.
"foo.lsp" name: "foo" type: "lsp" "a.b.c" name: "a.b" type: "c"
If a namestring ends with a period, the filetype becomes the null string.
"foo." name: "foo" type: "" (null string)
If a namestring begins with a period, the file name becomes ().
".lsp" name: nil type: "lsp"
If a namestring contains no period, the filetype is ().
"foo" name: "foo" type: nil
In a pathname, the file directory is represented as a list which
always begins with either :relative
or :absolute
"common/demo/foo.lsp" ";common;demo;foo.lsp" directory: (:relative "common" "demo") name: "foo" type: "lsp" "/common/demo/foo.lsp" "common;demo;foo.lsp" directory: (:absolute "common" "demo") name: "foo" type: "lsp"
If a namestring does not contain a directory, the directory component of the pathname is ().
"foo.lsp" directory: nil name: "foo" type: "lsp"
The abbreviation symbols `.
' and `..
' may be used in a
namestring, but only the second one is translated to a standard
keyword
"./demo/queen.lsp" directory: (:relative "." "demo") name: "queen" type: "lsp" "../../demo/queen.lsp" directory: (:relative @pxlref{:up} :up "demo") name: "queen" type: "lsp"
The part of a namestring after the last directory separator (`/
'
or `;
') is always regarded as representing the file name and the
filetype. In order to represent a pathname with both the name and the
filetype (), end the pathname with a slash.
"/usr/common/" directory: (:absolute "usr" "common") name: nil type: nil "/usr/common/.lsp" directory: (:absolute "usr" "common") name: ".lsp" type: nil
`*
' in the place of file name or filetype becomes :wild
"*.lsp" name: :wild type: "lsp" "foo.*" name: "foo" type: :wild