est ici une solution non optimale. Dans ce cas, l'UFD doit avoir un nom spécifique, qui est transmis au script qui recherche chaque lettre de lecteur possible pour une correspondance. Il n'est probablement pas pratique de s'appuyer sur les lecteurs flash ayant tous le même nom.
Toujours en espérant que quelqu'un arrive avec une meilleure réponse!
setlocal
:: Initial variables
set TMPFILE=%~dp0getdrive.tmp
set driveletters=abcdefghijklmnopqrstuvwxyz
set MatchLabel_res=
for /L %%g in (2,1,25) do call :MatchLabel %%g %*
if not "%MatchLabel_res%"=="" echo %MatchLabel_res%
goto :END
:: Function to match a label with a drive letter.
::
:: The first parameter is an integer from 1..26 that needs to be
:: converted in a letter. It is easier looping on a number
:: than looping on letters.
::
:: The second parameter is the volume name passed-on to the script
:MatchLabel
:: result already found, just do nothing
:: (necessary because there is no break for for loops)
if not "%MatchLabel_res%"=="" goto :eof
:: get the proper drive letter
call set dl=%%driveletters:~%1,1%%
:: strip-off the " in the volume name to be able to add them again further
set volname=%2
set volname=%volname:"=%
:: get the volume information on that disk
vol %dl%: > "%TMPFILE%" 2>&1
:: Drive/Volume does not exist, just quit
if not "%ERRORLEVEL%"=="0" goto :eof
set found=0
for /F "usebackq tokens=3 delims=:" %%g in (`find /C /I "%volname%" "%TMPFILE%"`) do set found=%%g
:: trick to stip any whitespaces
set /A found=%found% + 0
if not "%found%"=="0" set MatchLabel_res=%dl%:
goto :eof
:END
if exist "%TMPFILE%" del "%TMPFILE%"
endlocal
Cette solution semble évidente maintenant que vous la présentez. Je parie que cela signifie que c'est la bonne réponse. Je dois attendre le matin pour l'implémenter, cependant. Merci!! –
Cela a fonctionné très bien! Merci encore. –
Les solutions les plus simples sont généralement les meilleures, heureux que je puisse aider. – Tester101