H
Howard Brazee
Sometimes a removable drive on a networked computer has a different
drive letter than I had the previous time.
How can I write a cleaner batch file that accesses a drive by name? I
know the name, but the letter might be variable.
The following code works - but it is ugly code:
echo on
set mydrive=D:
dir %mydrive% 2>NUL | FIND /i "Brazee" >NUL
@If ErrorLevel 1 goto :tryE
@If not ErrorLevel 1 goto :foundIt
@If ErrorLevel 1 goto :Finale
pause You should not get here
:TryE
set mydrive=E:
dir %mydrive% 2>NUL | FIND /i "Brazee" >NUL
@If ErrorLevel 1 goto :tryF
@If not ErrorLevel 1 goto :foundIt
@If ErrorLevel 1 goto :Finale
pause You should not get here
:TryF
set mydrive=E:
dir %mydrive% 2>NUL | FIND /i "Brazee" >NUL
@If ErrorLevel 1 goto :tryG
@If not ErrorLevel 1 goto :foundIt
@If ErrorLevel 1 goto :Finale
pause You should not get here
:TryG
set mydrive=G:
dir %mydrive% 2>NUL | FIND /i "Brazee" >NUL
@If ErrorLevel 1 goto :tryH
@If not ErrorLevel 1 goto :foundIt
@If ErrorLevel 1 goto :Finale
pause You should not get here
:TryH
echo failure
goto :finale
:foundIt
pause foundit
:Finale
pause exit
drive letter than I had the previous time.
How can I write a cleaner batch file that accesses a drive by name? I
know the name, but the letter might be variable.
The following code works - but it is ugly code:
echo on
set mydrive=D:
dir %mydrive% 2>NUL | FIND /i "Brazee" >NUL
@If ErrorLevel 1 goto :tryE
@If not ErrorLevel 1 goto :foundIt
@If ErrorLevel 1 goto :Finale
pause You should not get here
:TryE
set mydrive=E:
dir %mydrive% 2>NUL | FIND /i "Brazee" >NUL
@If ErrorLevel 1 goto :tryF
@If not ErrorLevel 1 goto :foundIt
@If ErrorLevel 1 goto :Finale
pause You should not get here
:TryF
set mydrive=E:
dir %mydrive% 2>NUL | FIND /i "Brazee" >NUL
@If ErrorLevel 1 goto :tryG
@If not ErrorLevel 1 goto :foundIt
@If ErrorLevel 1 goto :Finale
pause You should not get here
:TryG
set mydrive=G:
dir %mydrive% 2>NUL | FIND /i "Brazee" >NUL
@If ErrorLevel 1 goto :tryH
@If not ErrorLevel 1 goto :foundIt
@If ErrorLevel 1 goto :Finale
pause You should not get here
:TryH
echo failure
goto :finale
:foundIt
pause foundit
:Finale
pause exit