% $Id: cdx.tex 1.2 1998/01/04 03:07:13 brian Exp $

\chapter{cdx---Enhanced Change Directory}

The \textbf{cdx} command is an enhanced (eXtended) version of the CD
(or CHDIR) command. Like CD, it can go to a specified directory.
Unlike CD, it can also change the current drive at the same time. It
can go to a default HOME directory. And it can search through a set of
paths for the specified directory, eliminating the need for a lot of
little command files to change directories.

The \textbf{c:$\backslash$tmp} directory must exist and be writable
for the Win32 and OS/2 versions of \textbf{cdx}. A temporary batch
(command) file is written to \textbf{c:$\backslash$tmp} by the
\textbf{cdx} command for these platforms.

On DOS, the \textbf{cdx} command is implemented as \textbf{cdx.bat}.
The \textbf{cdx.bat} script calls \textbf{cdir.exe} and
\textbf{cdir.exe} changes the current directory and drive itself.

For Win32, the \textbf{cdx} command is implemented as the
\textbf{cdx.bat} script. For OS/2, it is implemented as the
\textbf{cdx.cmd} script. For these platforms, \textbf{cdx} calls
\textbf{cdir.exe} just to get the path and drive change information
and then \textbf{cdx} itself performs the change. This is because
these platforms, like Unix, don't allow a process to change its parent
process's environment or working directory.

For DOS, the cdx.bat file just invokes the cdir.exe program. You can, if
you wish, run the cdir.exe program directly to change your current
working drive and path. Using \textbf{cdx} instead just lets your fingers type
the same command on DOS, OS/2, and Win32.

This command cannot be named cd, which is the name of the less-capable
built-in DOS, Win32, and OS/2 command.

\section{Usage}

\verb+ cdx  [d:][path]+
\medskip

If both the drive and path are missing, then \textbf{cdx} attempts to
change the current drive and path to that specified by the HOME
environment variable.

If the drive is present, then \textbf{cdx} changes your current drive
to that drive. If the path is present, then \textbf{cdx} changes the
current directory on that drive to the the specified path.

If the drive is missing and the path is relative (doesn't begin with
\verb+\+ or \verb+/+ path separator), then \textbf{cdx} looks in the
current directory for that path. If it doesn't find it, it then looks
for the path in the directories specified by the CDPATH environment
variable. The list of paths specified by CDPATH should be formatted
just like those for the PATH environment variable.

The following are the settings for HOME and CDPATH that I use:

\begin{itemize}
\item[{}]
\begin{verbatim}
SET HOME=c:\u\brian
SET CDPATH=c:\u\brian;c:\Program Files;e:\watcom
\end{verbatim}
\end{itemize}

\section{Examples}

The following examples use the settings for HOME and CDPATH shown above.

\begin{enumerate}

\item \verb+cdx+

        Go to the \verb+c:\u\brian+ (HOME) directory.

\item \verb+cdx a:+

        Go to the current directory on the \texttt{A} drive.

\item \verb+cdx d:/tmp+

        Go to the \verb+\tmp+ directory on the \texttt{D} drive.

\item \verb+cdx include+

        Go to the \textbf{include} directory within the current
        directory. If it doesn't exist, then use the list of
        directoies in CDPATH and go to the first of the following
        directories that exists:

        \begin{itemize}
        \item[{}]
\begin{verbatim}
c:\u\brian\include
c:\Program Files\include
e:\watcom\include
\end{verbatim}
        \end{itemize}

\end{enumerate}
