Next: , Previous: , Up: Pathnames   [Contents][Index]


15.1.3 Operations on Pathnames

procedure: pathname? object

Returns #t if object is a pathname; otherwise returns #f.

procedure: pathname=? pathname1 pathname2

Returns #t if pathname1 is equivalent to pathname2; otherwise returns #f. Pathnames are equivalent if all of their components are equivalent, hence two pathnames that are equivalent must identify the same file or equivalent partial pathnames. However, the converse is not true: non-equivalent pathnames may specify the same file (e.g. via absolute and relative directory components), and pathnames that specify no file at all (e.g. name and directory components unspecified) may be equivalent.

procedure: pathname-absolute? pathname

Returns #t if pathname is an absolute rather than relative pathname object; otherwise returns #f. Specifically, this procedure returns #t when the directory component of pathname is a list starting with the symbol absolute, and returns #f in all other cases. All pathnames are either absolute or relative, so if this procedure returns #f, the argument is a relative pathname.

procedure: directory-pathname? pathname

Returns #t if pathname has only directory components and no file components. This is roughly equivalent to

(define (directory-pathname? pathname)
  (string-null? (file-namestring pathname)))

except that it is faster.

procedure: pathname-wild? pathname

Returns #t if pathname contains any wildcard components; otherwise returns #f.

procedure: merge-pathnames pathname [defaults [default-version]]

Returns a pathname whose components are obtained by combining those of pathname and defaults. Defaults defaults to the value of param:default-pathname-defaults and default-version defaults to newest.

The pathnames are combined by components: if pathname has a non-missing component, that is the resulting component, otherwise the component from defaults is used. The default version can be #f to preserve the information that the component was missing from pathname. The directory component is handled specially: if both pathnames have directory components that are lists, and the directory component from pathname is relative (i.e. starts with relative), then the resulting directory component is formed by appending pathname’s component to defaults’s component. For example:

(define path1 (->pathname "scheme/foo.scm"))
(define path2 (->pathname "/usr/morris"))
path1
     ⇒  #[pathname 74 "scheme/foo.scm"]
path2
     ⇒  #[pathname 75 "/usr/morris"]
(merge-pathnames path1 path2)
     ⇒  #[pathname 76 "/usr/scheme/foo.scm"]
(merge-pathnames path2 path1)
     ⇒  #[pathname 77 "/usr/morris.scm"]

The merging rules for the version are more complex and depend on whether pathname specifies a name. If pathname does not specify a name, then the version, if not provided, will come from defaults. However, if pathname does specify a name then the version is not affected by defaults. The reason is that the version “belongs to” some other file name and is unlikely to have anything to do with the new one. Finally, if this process leaves the version missing, then default-version is used.

The net effect is that if the user supplies just a name, then the host, device, directory and type will come from defaults, but the version will come from default-version. If the user supplies nothing, or just a directory, the name, type and version will come over from defaults together.

parameter: param:default-pathname-defaults

The value of this parameter (see Parameters) is the default pathname-defaults pathname; if any pathname primitive that needs a set of defaults is not given one, it uses this one. Modifying the working-directory-pathname parameter also changes this parameter to the same value, computed by merging the new working directory with the parameter’s old value.

variable: *default-pathname-defaults*

This variable is deprecated; use param:default-pathname-defaults instead.

procedure: pathname-default pathname device directory name type version

This procedure defaults all of the components of pathname simultaneously. It could have been defined by:

(define (pathname-default pathname
                          device directory name type version)
  (make-pathname (pathname-host pathname)
                 (or (pathname-device pathname) device)
                 (or (pathname-directory pathname) directory)
                 (or (pathname-name pathname) name)
                 (or (pathname-type pathname) type)
                 (or (pathname-version pathname) version)))
procedure: file-namestring pathname
procedure: directory-namestring pathname
procedure: host-namestring pathname
procedure: enough-namestring pathname [defaults]

These procedures return a string corresponding to a subset of the pathname information. file-namestring returns a string representing just the name, type and version components of pathname; the result of directory-namestring represents just the host, device, and directory components; and host-namestring returns a string for just the host portion.

enough-namestring takes another argument, defaults. It returns an abbreviated namestring that is just sufficient to identify the file named by pathname when considered relative to the defaults (which defaults to the value of param:default-pathname-defaults).

(file-namestring "/usr/morris/minor.van")
     ⇒  "minor.van"
(directory-namestring "/usr/morris/minor.van")
     ⇒  "/usr/morris/"
(enough-namestring "/usr/morris/men")
     ⇒  "men"      ;perhaps
procedure: file-pathname pathname
procedure: directory-pathname pathname
procedure: enough-pathname pathname [defaults]

These procedures return a pathname corresponding to a subset of the pathname information. file-pathname returns a pathname with just the name, type and version components of pathname. The result of directory-pathname is a pathname containing the host, device and directory components of pathname.

enough-pathname takes another argument, defaults. It returns an abbreviated pathname that is just sufficient to identify the file named by pathname when considered relative to the defaults (which defaults to the value of param:default-pathname-defaults).

These procedures are similar to file-namestring, directory-namestring and enough-namestring, but they return pathnames instead of strings.

procedure: directory-pathname-as-file pathname

Returns a pathname that is equivalent to pathname, but in which the directory component is represented as a file. The last directory is removed from the directory component and converted into name and type components. This is the inverse operation to pathname-as-directory.

(directory-pathname-as-file (->pathname "/usr/blisp/"))
     ⇒  #[pathname "/usr/blisp"]
procedure: pathname-as-directory pathname

Returns a pathname that is equivalent to pathname, but in which any file components have been converted to a directory component. If pathname does not have name, type, or version components, it is returned without modification. Otherwise, these file components are converted into a string, and the string is added to the end of the list of directory components. This is the inverse operation to directory-pathname-as-file.

(pathname-as-directory (->pathname "/usr/blisp/rel5"))
     ⇒  #[pathname "/usr/blisp/rel5/"]

Next: , Previous: , Up: Pathnames   [Contents][Index]