Nomear um volume difere de < href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx"> Nomeando arquivos, caminhos e espaços para nome .
O próximo script mostra a possível abordagem de como obter a letra da unidade atualmente atribuída a um volume. Usa a classe Win32_Volume :
The
Win32_Volume
class represents an area of storage on a hard disk. The class returns local volumes that are formatted, unformatted, mounted, or offline. A volume is formatted by using a file system, such asFAT
orNTFS
, and might have a drive letter assigned to it. One hard disk can have multiple volumes, and volumes can span multiple physical disks. TheWin32_Volume
class does not support disk drive management.
@ECHO OFF
SETLOCAL EnableExtensions DisableDelayedExpansion
call :getDriveLetter "\?\Volume{5c729d19-70f7-11e5-830d-ac220b50824f}\"
call :getDriveLetter "\?\Volume{090c044f-7ccc-11e4-824e-806e6f6e6963}\"
call :getDriveLetter "\?\Volume{de60a588-fbe5-11e4-826f-806e6f6e6963}\"
:endlocal
ENDLOCAL
goto :eof
:getDriveLetter
set "_volumeID=%~1"
set "_DriveLetter="
for /F "tokens=1,* delims==" %%G in ('
wmic volume where "DeviceID='%_volumeID:\=\%'" get DriveLetter /value
') do for /F %%g in ("%%~H") do set "_%%~G=%%~g"
call :doSomething
goto :eof
:doSomething
rem only output for debugging
if defined _DriveLetter (
echo %_volumeID% DriveLetter %_DriveLetter%
) else (
echo %_volumeID% DriveLetter unknown
)
goto :eof
Saída :
d:\temp> D:\bat\SU63592.bat
\?\Volume{5c729d19-70f7-11e5-830d-ac220b50824f}\ DriveLetter F:
\?\Volume{090c044f-7ccc-11e4-824e-806e6f6e6963}\ DriveLetter unknown
\?\Volume{de60a588-fbe5-11e4-826f-806e6f6e6963}\ DriveLetter E: