Next: , Previous: , Up: Operating-System Interface   [Contents][Index]


15.2 Working Directory

When MIT/GNU Scheme is started, the current working directory (or simply, working directory) is initialized in an operating-system dependent manner; usually, it is the directory in which Scheme was invoked. The working directory can be determined from within Scheme by calling the pwd procedure, and changed by calling the cd procedure. Each REP loop has its own working directory, and inferior REP loops initialize their working directory from the value in effect in their superior at the time they are created.

parameter: working-directory-pathname
parameter: pwd

Returns the current working directory as a pathname that has no name, type, or version components, just host, device, and directory components. pwd is an alias for working-directory-pathname; the long name is intended for programs and the short name for interactive use.

This parameter may be called with an argument to set its value, in which case it also modifies the value of param:default-pathname-defaults by merging the new working directory into it.

procedure: set-working-directory-pathname! filename
procedure: cd filename

This procedure is deprecated; instead call working-directory-pathname with an argument.

Makes filename the current working directory and returns the new current working directory as a pathname. Filename is coerced to a pathname using pathname-as-directory. cd is an alias for set-working-directory-pathname!; the long name is intended for programs and the short name for interactive use.

Additionally, set-working-directory-pathname! modifies the value of param:default-pathname-defaults by merging the new working directory into it.

When this procedure is executed in the top-level REP loop, it changes the working directory of the running Scheme executable.

(set-working-directory-pathname! "/usr/morris/blisp")
     ⇒  #[pathname "/usr/morris/blisp/"]
(set-working-directory-pathname! "~")
     ⇒  #[pathname "/usr/morris/"]

This procedure signals an error if filename does not refer to an existing directory.

If filename describes a relative rather than absolute pathname, this procedure interprets it as relative to the current working directory, before changing the working directory.

(working-directory-pathname)
     ⇒  #[pathname "/usr/morris/"]
(set-working-directory-pathname! "foo")
     ⇒  #[pathname "/usr/morris/foo/"]
procedure: with-working-directory-pathname filename thunk

This procedure is deprecated; instead bind working-directory-pathname using parameterize.

This procedure dynamically binds the current working directory to filename and returns the value of thunk (a procedure of no arguments). Filename is coerced to a pathname using pathname-as-directory. In addition to binding the working directory, with-working-directory-pathname also dynamically binds the param:default-pathname-defaults parameter, merging the old value with the new working directory pathname.


Next: , Previous: , Up: Operating-System Interface   [Contents][Index]