Access drive by name

  • Thread starter Thread starter Howard Brazee
  • Start date Start date
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
 
This is not a newsgroup for writing batch files - sorry

XP has a bug with flash drives & assigning drive letters. Try assigning a
letter like Z to it & see it that holds it.
 
Back
Top