Page 1 of 1

Make a script independent of the System drive letter

Posted: 10 May 2008 16:37
by budhax
Hello,
In some case, the "System drive letter" is different of C:, and a script can use an absolute path like C:\folder\bla.
So, this script cannot works if MS Windows is installed in a difference drive letter of C:

Here is a script using an absolute path in the C: drive (where C: is the System drive letter).

Code: Select all

@ECHO OFF
SETLOCAL
IF NOT EXIST "C:\PROGRAM Files\WinRAR" (ECHO *** WinRAR is missing&Pause&EXIT)
SET PATH="C:\PROGRAM Files\WinRAR\";%PATH%
:: Then do something using WinRAR
ENDLOCAL


Is this method enough and safe to make the script independent of the "System drive letter"?
METHOD:
- add a variable: SET SD=%SYSTEMDRIVE%
- replace all absolute drive C: by %SD%

Any comment?
Thanks and regards.

Code: Select all

@ECHO OFF
SETLOCAL
SET SD=%SYSTEMDRIVE%
IF NOT EXIST "%SD%\PROGRAM Files\WinRAR" (ECHO *** WinRAR is missing&Pause&EXIT)
SET PATH="%SD%\PROGRAM Files\WinRAR\";%PATH%
:: Then do something using WinRAR
ENDLOCAL

Posted: 12 May 2008 15:36
by jeb
Hi Budhax,

Is this method enough and safe to make the script independent of the "System drive letter"?


yes and no.

yes it is enough to independent of the drive letter.

but it's useless because "Program Files" is not static, on my XP System it's called "Programme".
If you will independent better use %ProgramFiles%

Code: Select all

@ECHO OFF
SETLOCAL
SET SD=%SYSTEMDRIVE%
IF NOT EXIST "%ProgramFiles%\WinRAR" (ECHO *** WinRAR is missing&Pause&EXIT)
SET PATH="%ProgramFiles%\WinRAR\";%PATH%
:: Then do something using WinRAR
ENDLOCAL


jeb