Link to home
Start Free TrialLog in
Avatar of cmoore1
cmoore1

asked on

Need to pass current drive letter to various batch files.

I am running system commander on a laptop to allow me to use XP or DOS 6.22 for differant applications. Some of the bacth files I run from Dos I would like to run from XP. My problem is when booting from XP the batch files are on drive e & f. When booting from dos they are on drive d & e. I am trying to identify the drive drive I start from and then Increment to the correct drive using dos variable to allow the batch files to run correctly. I can get the drive letter in an xp batch file, but it doesn't run in dos. I can also get the drive letter in a "C" file, but don't know how to pass it to a dos variable.
Avatar of Qlemo
Qlemo
Flag of Germany image

In pure DOS, you can try to do something like


for %%D in (C D E F G) do if exist %%D:somefile set drive=%%D


The somefile has to be a file which exists only on the drive you want to use.
ASKER CERTIFIED SOLUTION
Avatar of itsmeandnobodyelse
itsmeandnobodyelse
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AmazingTech
AmazingTech

Option1:
XP(windows) sets up many more environment variables than DOS 6.22 I would check for one of the windows variable and adjust accordingly.

if defined systemroot (Set BatchFiles=E:\BatchFiles) Else (Set BatchFiles=D:\BatchFiles)

Option2:
DOS 6.22
AUTOEXEC.BAT
Set BatchFiles=D:\BatchFiles

XP
Setup a system environment variable
REG ADD "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" /v "BatchFiles" /t REG_SZ /f /d "E:\BatchFiles"
Oh. One more thing your batch files on d & e or e & f could call it's own drive letter with

%~d0

%0 inside your batch file is your batch file typically how you invoked it.

Try some of these:
ECHO How did I call this batch file = %0
ECHO Show me the full path of the batch file = %~f0
ECHO Show me the drive the batch file is on = %~d0
ECHO Show me the path the batch file is on = %~p0
ECHO Show me the drive and path the batch file is on = %~dp0
ECHO Show me the drive, path and the filename without extension = %~dpn0
ECHO Show me the file extension = %~x0

For more %~ check out "for /?"