Batch: Switch drive, if not C:

March 5, 2009 at 14:36:05
Specs: Windows XP
It's rare that I could use a batch file, and this is one of those times. I can't remember too much about the finer points on batch language, so I need to ask.

I'm looking for a batch file line that compares drive letters to see if it is being run on C: drive, and if it isn't, to change drives before proceeding further. If I can can get this, I can do the rest as far as my batch file.


See More: Batch: Switch drive, if not C:

Report •


#1
March 5, 2009 at 15:00:37
This will switch to c: or do nothing if you're already there.

c:


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#2
March 5, 2009 at 17:17:35
Duuuuuh.
Sometimes in life a person tries to make something that was always simple, and tries to make it very complicated. That's what I get from spending too much time at different batch sites trying to figure out how to do this.

Constant exposure to complexity tends to cloud a person's mind from seeing the purely simple. I'll give it a try tomorrow and report back here if it doesn't fit in to what I'm needing.


Report •

#3
March 5, 2009 at 22:30:54
If you need the root of the drive you may want to use:

cd /d c:\

If you only use "c:" and the c: drive is already expanded to a directory(eg c:\windows>) the directory will remain.


Report •

Related Solutions

#4
March 7, 2009 at 11:15:11
Okay, the cd /d c:\ is useful, but I still can’t get to where I want to be.

I guess the easiest thing would be to tell what I’m trying to do overall.

What I’m trying to do is create a batch that whenever it is ran, it always checks to make sure if it’s in specific directory on C:\. If it’s not there, then make the directory and then copy itself into it. From there, it will install itself into the “Task Scheduler” to be ran at a certain time or date. Running this on a schedule would bring up NOTEPAD.EXE with a text file.

The batch is self installing if it doesn’t exists, and then it runs if it is (through the task scheduler).


Report •

#5
March 7, 2009 at 11:44:02
if not exist e:\mystuff\test.bat (
md e:\mystuff
copy test.bat e:\mystuff
)
cd /d e:\mystuff
test


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#6
March 7, 2009 at 12:14:30
Thanks! That does it!

Report •


Ask Question