batch for CD followed by switching drives

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
pmennen
Posts: 18
Joined: 15 Jul 2011 02:10

batch for CD followed by switching drives

#1 Post by pmennen » 15 Jul 2011 02:52

I found a very old DOS utility called CWD which behaves like CD but then switches drives.
For example, if the current drive is "C", and I type:

CWD F:\abc

This would be the equivalent of the two commands:
CD F:\abc
F:

It's complicated to explain why I need CWD, but take it for granted that I do.
The only problem with CWD is that it is so old it will only work on dos 8.3 file names.
I would like an equivalent program or batch file that can do the same as CWD but that will work with long folder names.

Some newer versions of CD offer an optional argument "/D" that does exactly this (changes to the drive as well).
So the command:
CD /D F:\abc
would do exactly what I need. Unfortunately I'm trying to use the dos provided by the "DosBox" utility, and the CD command contained in that doesn't have this optional parameter. (darn.) So I would like to find another way.

One idea I had is too see if there was any utility that could extract the first 2 characters of a command, and run that.
Suppose I found such a program (say called FRST2). Then I could make my wanted batch file as follows:

CD %1
FRST2 %1

Since the first two characters of the argument will always be the drive letter followed by a colon (in my situation) this would work for me.

Of course, I don't know if there are any functions out there like FRST2, so this is just a wild stab.
Perhaps some of you know of such a function, or can think of a simpler way to accomplish what I need.

Thanks
~Paul

alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

Re: batch for CD followed by switching drives

#2 Post by alan_b » 16 Jul 2011 03:08

A single line BAT which I will call DirCD.bat

Code: Select all

%1 & CD %2


To switch to a new directory D: and directory \Utils simply invoke
DirCD D: \Utils


Alan

Post Reply