_____USAGE MYCD [[$env_var] [d:][path/]directory] _____DESCRIPTION MYCD is an alternative to the MS-DOS(tm) cd command that offers shortcut ways to change the current directory [or drive]. MYCD interprets wildcards, forward and reverse slashes, dots, environmental variables, and will use a variable CDPATH, if defined, to direct its search pattern for a directory. An environmental variable is given by preceding it by a '$' or a '%'. For example, if there is an environmental variable SRC, "MYCD $src" (or "MYCD %src" ) will change to the directory defined by SRC. An environmental variable can precede a path ( "MYCD $src/pa*" ), but any '$' or '%' will be interpreted literally when interior to the path. MYCD will deal with a drive request ( "MYCD d:..." ) by actually changing to the drive specified. This is different than MS-DOS's cd behavior, where under the same circumstances, the current directory on the drive is changed, but the present working directory remains the same (no drive change). After dealing with the drive information, MYCD has the same notion of `absolute' or `relative' changes of directory as does the MS-DOS cd. If the path requested, after being stripped of any drive information, begins with a slash, then the path change is interpreted relative to the root directory. Thus, the following absolute changes are determined: MYCD \path change to \path on current drive MYCD d:\path change to \path on drive d: The alternative is that the path is considered as a relative path. If an environmental variable CDPATH is _not_ set, changes are made relative to the current directory. For example, "MYCD dog" will change to the subdirectory dog of the current directory, if there is one. General examples (with "path" having no leading slash): MYCD path change to path relative to current dir, on current drive MYCD d: change to current dir on drive d: MYCD d:path change to path relative to current dir on drive d: MYCD [no args] change to root dir (\) on current drive (an exception) If an environmental variable CDPATH is specified (e.g., with the MS-DOS SET command), MYCD's changes relative to a current directory are modified. That is, MYCD will deal with `absolute' paths having a slash at the beginning, or paths beginning with an environmental variable, just as described above, but will deal with other paths relative to the contents of CDPATH. CDPATH is a list of paths, delimited by ';', similar to PATH. For example, "set CDPATH=.;\;c:\;e:\upload;..;h:\work". MYCD will successively treat each of the paths specified as the current directory, and try to change relative to that directory. For example, with the above CDPATH, "MYCD rep*/d*" will change to h:\work\reports\daily if h:\work is the first entry with a subdirectory name matching the pattern "rep*/d*". A judicious setting of CDPATH is very valuable; note that it is the PARENTS of frequently accessed paths that should be specified in CDPATH. For example, the choice "e:\upload" above, should mean that you wish to access various subdirectories of e:\upload by name, not that e:\upload is frequently accessed. It would be strange to have anything other than '.' as the first entry in CDPATH, so be sure to do this! MYCD allows wildcards '*' and '?' throughout the path. These are interpreted in the MS-DOS style and a change will be made to the first matching directory found by MS-DOS (no attempt is made to resolve ambiguity). For example, if you have subdirs bat, batch, backup, bad.dir and you issue "MYCD ba*d*" you can land in any of these except bad.dir. (This is what MS-DOS function calls do (sigh). If you are confused, look up wildcards in your MS-DOS manual.) MYCD deals equally well with forward and reverse slashes. It will reduce multiple consecutive slashes to just one slash. It also understands "." as the current directory and ".." as a parent, when delimited anywhere in a given path. Thus "MYCD cow\dog//./\\..\/cat\" is equivalent to "MYCD cow\cat". As a bonus, 3 dots mean grandparent directory (e.g., "MYCD c:\x\y\z\..." <-> "MYCD c:\x" or MYCD e:... <-> MYCD e:../.. ), and 4 dots for great-grandparent,... MYCD sets the MS-DOS errorlevel to 1 if it fails to change directory. MYCD does not print anything unless an error occurs. _____HINTS Copy MYCD.com to a ramdisk (d:\ say) at boot time and use an aliasing to make cd a synonym for d:\mycd. (Since the surrogate cd command will not be part of command.com, you want it to load and execute as quickly as possible.) It is not a good idea to put into CDPATH any path that begins with a floppy drive that is sometimes empty: you have instructed MYCD to look there. If you get the "Not ready error reading drive X" message while executing MYCD, processing will be aborted unless you put a valid disk in the drive and retry. A request "MYCD $dirname" with the intent of changing to a directory whose name begins with '$' will fail. If you actually give directories names beginning with '$' or '%', hide this from MYCD. For example, use "MYCD ./$dirname". _____BUGS and LIMITATIONS Resolution of wildcards can cause some surprises. If subdir aaa has subdirs bb1 and bb2; and bb2 has subdir cc3, the request "MYCD a*/b*/c*" may or may not work, depending on the directory ordering maintained by MS-DOS. The path may expand as aaa/b*/c* to aaa/bb1/c*, for which there is no match; or it may expand as aaa/b*/c* to aaa/bb2/c* to aaa/bb2/cc3. I don't think that the extra complexity needed to deal with the generality of situations like this is warranted. Environmental variables are treated as upper case, which is normal for MS-DOS. For example, "set src=f:\srcdir" actually stores an environmental variable named SRC. If you use some utility and put mixed case in environmental variables, MYCD will not find these. When an environmental variable is specified as the initial part of an argument, MYCD does not use CDPATH. For example, "set up=.." and "MYCD $up" will operate, but "set b=b*" and "cd $b" will look for a directory "./b*", which isn't very useful. The lesson here is to use environmental variables that specify a relative motion or include drive and complete path. The number of characters in the full name of the path of the new directory cannot exceed 127 characters. CDPATH cannot contain more than 191 characters. Results are unpredictable if these limits are exceeded. MYCD says its name as "cd" in error messages, regardless of what you call it. _____AUTHOR J. Martin Borden att!granjon!marty or marty%garage.att.com There is no warrantee, expressed or implied, with this distribution.