Make a script independent of the System drive letter
Posted: 10 May 2008 16:37
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).
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.
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