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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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\CurrentContro lSet\Contr ol\Session Manager\Environment" /v "BatchFiles" /t REG_SZ /f /d "E:\BatchFiles"
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\CurrentContro
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 /?"
%~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 /?"
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.