User forums > General (but related to Code::Blocks)
OT: Windows XP Batch file to set USB Drive Letter
(1/1)
stahta01:
I am experimenting with using Code::Blocks on an USB Drive and decided it is easier to always use the same Drive Letter for some Compilers.
Here's the batch file I use to set the USB Drive to "G:"
I copy the batch file to the root folder on the USB Drive and run it manually when needed.
It is only needed once per computer in my experience.
Tim S.
MntAsG.bat
--- Code: ---@ECHO OFF
REM
REM Change Current USB Drive to be on TARGETDRV Drive Letter.
REM
REM Change to root of Current Drive
CD \
REM Check the current drive is removable.
FOR /F "delims=" %%x IN ('fsutil fsinfo drivetype %CD% ^| FIND /i "removable"') DO SET DF=%%x
IF "%DF%"=="" GOTO ERROR1
echo mountvol %CD% /D > %TEMP%\mountdrv.bat
mountvol %CD% /L >%TEMP%\mountdrv.tmp
setlocal enabledelayedexpansion
SET TARGETDRV=G:
REM Check the TARGETDRV is NOT being used.
FOR /F "delims=" %%x IN ('MOUNTVOL %TARGETDRV% /L') DO SET DF=%%x
IF NOT "%DF%"=="The system cannot find the file specified." GOTO ERROR2
set LINE=mountvol %TARGETDRV%
for /f %%a in (%TEMP%\mountdrv.tmp) do (
set LINE=!LINE!%%a
)
echo %LINE% >> %TEMP%\mountdrv.bat
del /q %TEMP%\mountdrv.tmp
endlocal
REM echo PAUSE >> %TEMP%\mountdrv.bat
type %TEMP%\mountdrv.bat
REM PAUSE
cd /d "%HOMEDRIVE%%HOMEPATH%"
%TEMP%\mountdrv.bat
goto eof
:ERROR1
ECHO Current Drive is not removable.
endlocal
goto eof
:ERROR2
ECHO %TARGETDRV% is already in use.
endlocal
goto eof
:eof
PAUSE
--- End code ---
ollydbg:
Thanks for sharing!!
In my Windows XP system, the Driver G is already used for a DVD drive. So, this batch file will always give a error message:
--- Quote ---Current Drive is not removable.
Press any key to continue . . .
--- End quote ---
:D
stahta01:
--- Quote from: ollydbg on August 12, 2009, 04:52:11 pm ---Thanks for sharing!!
In my Windows XP system, the Driver G is already used for a DVD drive. So, this batch file will always give a error message:
--- Quote ---Current Drive is not removable.
Press any key to continue . . .
--- End quote ---
:D
--- End quote ---
Just set TARGETDRV to the drive you want to use.
--- Code: ---SET TARGETDRV=G:
--- End code ---
Navigation
[0] Message Index
Go to full version