我正在尝试编写一个批处理文件来将我的 dvd 翻录到硬盘上。我希望文件名成为 DVD 的卷标,但我无法确定在批处理文件中读取磁盘标签的方法。
有没有办法在批处理文件中检索驱动器的卷标,以便我可以将其用作文件名?
最佳答案
更全面。编程为我们有的子程序
@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
关于windows - 如何读取批处理文件中驱动器或卷的标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8649934/