Q. How can I return a drive letter for a given volume label or volume number?

Using Diskpart.exe, I have scripted FindLabel.bat to return a drive letter for a given volume label or volume number.

The syntax for using FindLabel.bat is:

\[call\] FindLabel "Volume or Label" Drive

Where:

Volume or Label is the string to match against, like Volume 1 or <label text>,
                where <label text> will be truncated to 11 characters.

Drive           is a call directed environment variable that will contain the drive letter, 
                like D:. If the Volume or Label is not found, Drive will contain 0:.
FindLabel.bat contains:
@echo off
if \{%2\}==\{\} @echo Syntax FindLabel "Volume or Label" Drive&goto :EOF
setlocal ENABLEDELAYEDEXPANSION
set label=%1
set label=%label:"=%
set FL="%TEMP%\dp.txt"
echo list volume>%FL%
echo exit>>%FL%
set label11=%LABEL:~0,11%
set DRV=0:
for /f "Tokens=*" %%a in ('diskpart /s %FL%^|find /i "%label11%"') do (
 set line=%%a
 set DRV=!line:~13,1!:
)
endlocal&set %2=%DRV%


Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish