• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1158
  • Last Modified:

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.
0
cmoore1
Asked:
cmoore1
  • 2
1 Solution
 
QlemoC++ DeveloperCommented:
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.
0
 
itsmeandnobodyelseCommented:
You could put the folder where the batches reside into PATH environment variable (define it in autoexec.bat for DOS and System Settings - System - Advanced - Environment Variables for XP) . Then you could call them without drive letter.

Or you do:

@echo off
set DRIVE=C:
dir %DRIVE%\mybatch.bat
if errorlevel 1 goto D_DRIVE
goto DONE
:D_DRIVE
set DRIVE=D:
dir %DRIVE%\mybatch.bat
if errorlevel 1 goto E_DRIVE
goto DONE
:E_DRIVE
...
:DONE

0
 
AmazingTechCommented:
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"
0
 
AmazingTechCommented:
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 /?"
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now