Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read the label of a drive or volume in a batch file?

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?

like image 271
jColeson Avatar asked Oct 29 '25 15:10

jColeson


1 Answers

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

like image 144
Timo Salmi Avatar answered Oct 31 '25 04:10

Timo Salmi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!