The CD procedure is used to set and/or change the current working directory. This routine changes the working directory for the IDL session and any child processes started from IDL during that session after the directory change is made. Under UNIX, CD does not affect the working directory of the process that started IDL. The PUSHD, POPD, and PRINTD procedures provide a convenient interface to CD.
IDL’s default current working directory depends on the platform and user interface:
- When using command-line mode, the default current working directory is the directory from which IDL was started.
- When using graphical mode, the default current working directory is controlled through the Initial working directory setting, located on the IDL Preferences page.
Examples
To specify a full path:
CD, '/home/data/'
To change to the january subdirectory of the current directory:
CD, 'january'
To change drives on a Windows system:
CD, 'C:'
To go back up a directory, use “..”. For example, if the current directory is /home/data/january, you could go up to the /home/data/ directory with the following command:
CD, '..'
If the current directory is /home/data/january, you could change to the /home/data/february directory with the following command:
CD, '../february'
To mimic the UNIX pwd command:
CD, CURRENT=c & PRINT, c
Syntax
CD [, Directory] [, CURRENT=variable]
Arguments
Directory
A scalar string specifying the path of the new working directory. If Directory is specified as an empty string, the working directory is changed to the user’s home directory (command-line mode) or to the directory specified by !DIR (graphical mode). If this argument is not specified, the working directory is not changed.
Note: On Windows systems, the CD command will treat either the backwards slash (\) or the forwards slash (/) as a directory separator character.
Keywords
CURRENT
If CURRENT is present, it specifies a named variable into which the current working directory is stored as a scalar string. The returned directory is the working directory before the directory is changed. Thus, you can obtain the current working directory and change it in a single statement:
CD, new_dir, CURRENT=old_dir
Note: The return value of the CURRENT keyword does not include a directory separator at the end of the string.
Version History
See Also
PUSHD, POPD