Iterate volume letters to find ID
Posted: 27 Nov 2014 05:05
G'Day,
I have ugly code which does what i need: takes letter by letter (Z --> C) in system and check the volume ID ("XXXX-XXXX"). Once correct volume is found, letter is assigned a variable (tdrive) and script proceeds.
Here is a code:
In what way this code can be changed in order to preserve functionality, but occupy less place and become more professional?
(some kind of iteration...?)
I have ugly code which does what i need: takes letter by letter (Z --> C) in system and check the volume ID ("XXXX-XXXX"). Once correct volume is found, letter is assigned a variable (tdrive) and script proceeds.
Here is a code:
Code: Select all
vol z: | find "XXXX-XXXX" >nul
if not errorlevel 1 (
set "tdrive=z:"
goto start
)
vol y: | find "XXXX-XXXX" >nul
if not errorlevel 1 (
set "tdrive=y:"
goto start
)
....
vol c: | find "XXXX-XXXX" >nul
if not errorlevel 1 (
set "tdrive=c:"
goto start
)
cls
echo.
echo.
echo target drive NOT found,
echo.
echo operation aborted.
pause >nul
goto :eof
:start
...
In what way this code can be changed in order to preserve functionality, but occupy less place and become more professional?
(some kind of iteration...?)