chdir

Function

Package: excl

Arguments: &optional directory

This function is designed to mimic the UNIX/DOS cd utility. In short, it extracts the directory component of directory and changes the current working directory to that. If the directory component is relative, the new directory is determined relative to the current working directory (as returned by current-directory). directory can be a pathname object or a string.

Note that this function does not modify the value of *default-pathname-defaults*. Therefore, after calling this function, it is likely that the current directory, as returned by current-directory, will be differrent from the directory specified in *default-pathname-defaults*. The related top-level command :cd does modify the value of *default-pathname-defaults*.

Because of a mismatch between UNIX and Common Lisp interpreting of strings naming directories, string arguments are handled specially, as we describe now. The following table shows the behavior of chdir given various values of pathname:

pathname is

Action by chdir

not specifiedChange to the current user's home directory on UNIX, to c:\ on Windows.
A pathname objectExtract the directory component of the pathname (translating first if it is a logical pathname). Change to that directory. Relative pathnames are resolved with respect to the current working directory (as returned by current-directory).
A string containing a /, : (colon), or ; (semicolon) naming a pathnameConvert to a pathname object, then continue as in item 1 of this table.
A string without a /, : (colon), or ; (semicolon).Add a / to the end of the string, convert to a pathname object, then continue as in item 1 of this table. See Note 1 below.

Examples. The current Unix user's home directory is /usr/tech/doe/. The directory /usr/tech/doe/tmp/ exists. The Allegro directory for the Lisp image is typically /acl5.0.1/ though your value may be different.

user(15): (chdir) ;; no argument: change to user home directory
"/usr/tech/doe/"
user(16): (chdir "sys:") ;; a string naming a logical pathname which translates
;; to the Allegro directory (the value you see may be different).
"/acl5.0.1/"
user(17): (chdir)
"/usr/tech/doe/"
user(18): (chdir "tmp") ;; change to the tmp/ subdirectory
"tmp/"
user(19): (chdir (make-pathname :directory "tmp")) ;; The absolute directory 
"/tmp/"
user(20): (chdir)
"/usr/tech/doe/"
user(21): 

Note 1. A / is added to the end of a string that does contain a /, ;, or : in order that (chdir "tmp") will work as `cd tmp' does in UNIX and DOS: change to the tmp subdirectory of the current directory. Following the ANSI CL spec, (make-pathname :directory "tmp") creates the absolute pathname object with namestring "/tmp/" while (make-pathname :directory "tmp/") creates the relative pathname with namestring "tmp/". It is the second that follows the UNIX paradigm. Appending a / guarantees that effect.

chdir returns the namestring of the directory component of the pathname changed to. Note that this may not be the new current directory (as returned by current-directory).

Warning about interaction between chdir and foreign loading and dumplisp: if the command line used to start Lisp identified the Allegro CL image with a relative pathname (`./mlisp', for example), you cannot do the first load of foreign code or dump an image with excl:dumplisp after changing the directory with this function. Therefore, if you started Lisp with a relative pathname, do at least one foreign load before calling chdir and do not call dumplisp after calling chdir. (The problem is that when doing the first foreign load or a dumplisp, Lisp needs to examine the running image, which it finds by examining the command line that invoked the image. If Lisp is identified on the command line with a relative pathname and the current directory has been changed, the relative pathname merged with the current directory no longer points to the running image. Changing back to the original current directory fixes the problem.)

See :cd, :popd, and :pushd, which also change the current directory. See also os-interface.htm for general information on the interface between in Allegro CL and the operating system.

The documentation is described in introduction.htm and the index is in index.htm.

Copyright (c) 1998-2000, Franz Inc. Berkeley, CA., USA. All rights reserved.

Created 2000.10.5.