Reputation: 971
I'm trying to write a batch file to rip my dvds to the hard drive. I'd like the file names to be the volume label of the dvd, but I haven't been able to determine a way to read the label of a disk in a batch file.
Is there a way to retrieve the volume label of a drive in a batch file so I can use it as the file name?
Upvotes: 4
Views: 16940
Reputation: 264
More fully. Programmed as a subroutine we have
@echo off & setlocal enableextensions
set target_=D:
::
call :IsDeviceReady %target_% isready_
echo Device %target_% ready: %isready_%
if /i "%isready_%"=="false" (endlocal & goto :EOF)
::
call :GetLabel %target_% label_
echo The label of Volume %target_% is %label_%
endlocal & goto :EOF
::
:IsDeviceReady
setlocal
set ready_=true
dir "%~1" > nul 2>&1
if %errorlevel% NEQ 0 set ready_=false
endlocal & set "%2=%ready_%" & goto :EOF
::
:GetLabel
setlocal
for /f "tokens=5*" %%a in (
'vol "%~1"^|find "Volume in drive "') do (
set label_=%%b)
endlocal & set "%2=%label_%" & goto :EOF
Originally from http://www.netikka.net/tsneti/info/tscmd101.htm#label
Upvotes: 5
Reputation: 29991
Try this:
for /f "tokens=1-5*" %%1 in ('vol') do (
set vol=%%6 & goto done
)
:done
echo %vol%
Upvotes: 3