Chapter 17. Filenames

17.1. Syntax
17.2. Wild pathnames and matching
17.3. C Reference
Filenames C dictionary — Common Lisp and C equivalence

17.1. Syntax

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 #P 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 and it can be roughly summarized as follows:

[hostname:][;][directory-item;]0 or more[name][.type[.version]]
  hostname = word
  directory-item = wildcard-word
  type, name = wildcard-word without dots

Here, wildcard-word is a sequence of any character excluding #\Null and dots. word is like a wildcard-word but asterisks are excluded.

The way ECL parses a namestring is by first looking for the hostname 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 hostname is not found or it is not a logical hostname, then ECL tries the physical pathname syntax

[device:][[//hostname]/][directory-item/]0 or more[name][.type]
  device, hostname = word
  directory-item = wildcard-word
  type = wildcard-word without dots
  name = [.]wildcard-word

If this syntax also fails, then the namestring is not a valid pathname string and a parse-error will be signalled.

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.

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 .bashrc, where the leading period indicates that the file is hidden.

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, ".*" is equivalent to (MAKE-PATHNAME :NAME ".*" :TYPE NIL), while (MAKE-PATHNAME :NAME NIL :TYPE :WILD) creates a pathname whose type is a wildcard.

The following table illustrates how the physical pathnames work with practical examples.

Table 17.1. Examples of physical namestrings

"ecl/build/bare.lsp""bare""lsp"(:relative "ecl" "build")NIL
"ecl/build/"NILNIL(:relative "ecl" "build")NIL
"../../ecl/build/"NILNIL(:relative :up :up "ecl" "build")NIL
"/etc/"NILNIL(:absolute "etc")NIL
"C:/etc/"NILNIL(:absolute "etc")"C"