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
@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