@echo off
setlocal
for %%i IN (c,e,x,y,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v) do (
if not defined second (call :TESTDRIVE %%i) else (goto :ALLDONE)
)
goto :eof
:TESTDRIVE
::redirect error output to command output, and compare output strings to figure out
::if drive is in use, unused, or an empty removeable media drive (eg: cdrom)
for /f "tokens=*" %%i in ('"dir %1: 2>&1"') do set response=%%i
set type=driveletter in use
if "%response%"=="The device is not ready." (set type=removeable drive)
if "%response%"=="The system cannot find the path specified." (set type=unused driveletter)
echo %1 %type%
if "%type%"=="unused driveletter" goto :MOUNTDRIVE
goto :eof
:MOUNTDRIVE
if not defined first (set first=%1) else (set second=%1)
echo this is where we would mount drive %1
goto :eof
:ALLDONE
echo All done! first driveletter is %first%, second is %second%
endlocal