Previous: Lisp Pathnames, Up: Pathnames
In some circumstances, what is wanted is a Lisp pathname object which corresponds to a string produced by the Operating System. In this case, some of the default parsing rules are inappropriate: most filesystems do not have a native understanding of wild pathnames; such functionality is often provided by shells above the OS, often in mutually-incompatible ways.
To allow the user to deal with this, the following functions are
provided: parse-native-namestring and native-pathname
return the closest equivalent Lisp pathname to a given string
(appropriate for the Operating System), while native-namestring
converts a non-wild pathname designator to the equivalent native
namestring, if possible. Some Lisp pathname concepts (such as the
:back directory component) have no direct equivalents in most
Operating Systems; the behaviour of native-namestring is
unspecified if an inappropriate pathname designator is passed to it.
Additionally, note that conversion from pathname to native filename
and back to pathname should not be expected to preserve equivalence
under equal.
Convert
thinginto a pathname, using the native conventions appropriate for the pathname hosthost, or if not specified the host ofdefaults. Ifthingis a string, the parse is bounded bystartandend, and error behaviour is controlled byjunk-allowed, as withparse-namestring. For file systems whose native conventions allow directories to be indicated as files, ifas-directoryis true, return a pathname denotingthingas a directory.
Convert
pathspec(a pathname designator) into a pathname, assuming the operating system native pathname conventions.
Construct the full native (name)string form of
pathname. For file systems whose native conventions allow directories to be indicated as files, ifas-fileis true and the name, type, and version components ofpathnameare allnilor:unspecific, construct a string that names the directory according to the file system's syntax for files.
Because some file systems permit the names of directories to be
expressed in multiple ways, it is occasionally necessary to parse a
native file name “as a directory name” or to produce a native file
name that names a directory “as a file”. For these cases,
parse-native-namestring accepts the keyword argument
as-directory to force a filename to parse as a directory, and
native-namestring accepts the keyword argument as-file
to force a pathname to unparse as a file. For example,
; On Unix, the directory "/tmp/" can be denoted by "/tmp/" or "/tmp".
; Under the default rules for native filenames, these parse and
; unparse differently.
(defvar *p*)
(setf *p* (parse-native-namestring "/tmp/")) => #P"/tmp/"
(pathname-name *p*) => NIL
(pathname-directory *p*) => (:ABSOLUTE "tmp")
(native-namestring *p*) => "/tmp/"
(setf *p* (parse-native-namestring "/tmp")) => #P"/tmp"
(pathname-name *p*) => "tmp"
(pathname-directory *p*) => (:ABSOLUTE)
(native-namestring *p*) => "/tmp"
; A non-NIL AS-DIRECTORY argument to PARSE-NATIVE-NAMESTRING forces
; both the second string to parse the way the first does.
(setf *p* (parse-native-namestring "/tmp"
nil *default-pathname-defaults*
:as-directory t)) => #P"/tmp/"
(pathname-name *p*) => NIL
(pathname-directory *p*) => (:ABSOLUTE "tmp")
; A non-NIL AS-FILE argument to NATIVE-NAMESTRING forces the pathname
; parsed from the first string to unparse as the second string.
(setf *p* (parse-native-namestring "/tmp/")) => #P"/tmp/"
(native-namestring *p* :as-file t) => "/tmp"