next up previous contents
Next: LS/DIR List Files Function Up: Operating System Functions Previous: Operating System Functions   Contents

Subsections

CD Change Working Directory Function

Usage

Changes the current working directory to the one specified as the argument. The general syntax for its use is

  cd('dirname')

but this can also be expressed as

  cd 'dirname'

or

  cd dirname

Examples of all three usages are given below. Generally speaking, dirname is any string that would be accepted by the underlying OS as a valid directory name. For example, on most systems, '.' refers to the current directory, and '..' refers to the parent directory. Also, depending on the OS, it may be necessary to ``escape'' the directory seperators. In particular, if directories are seperated with the backwards-slash character '\\', then the path specification must use double-slashes '\\\\'. Note: to get file-name completion to work at this time, you must use one of the first two forms of the command.

Example

The pwd command returns the current directory location. First, we use the simplest form of the cd command, in which the directory name argument is given unquoted.

--> pwd
ans = 
  <string>  - size: [1 34]
 /localhome/basu/FreeMat2/help/mtex
--> cd ..
--> pwd
ans = 
  <string>  - size: [1 29]
 /localhome/basu/FreeMat2/help

Next, we use the ``traditional'' form of the function call, using both the parenthesis and a variable to store the quoted string.

--> a = pwd;
--> cd(a)
--> pwd
ans = 
  <string>  - size: [1 34]
 /localhome/basu/FreeMat2/help/mtex

In the third version, we use only the quoted string argument without parenthesis.

--> cd '..'
--> pwd
ans = 
  <string>  - size: [1 29]
 /localhome/basu/FreeMat2/help


next up previous contents
Next: LS/DIR List Files Function Up: Operating System Functions Previous: Operating System Functions   Contents
Samit K. Basu 2005-03-16