ここで非最適なソリューションです。この場合、UFDには特定の名前が必要です。この名前は、一致するすべてのドライブ文字を検索するスクリプトに渡されます。同じ名前のフラッシュドライブに頼るのはおそらく現実的ではありません。
まだ誰かがより良い答えでポップすることを望んでいます!
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
このソリューションは、あなたがそれを提示した時点で明らかです。私はそれが正しい答えであることを意味します。しかし、これを実装するために朝まで待つ必要があります。ありがとう!! –
これは偉大な作業を巻き上げる!再度、感謝します。 –
最も簡単な解決策は、私が手伝ってくれてうれしいです。 – Tester101