我正试着写一个批处理文件来把我的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
源自http://www.netikka.net/tsneti/info/tscmd101.htm#label
试试这个:
for /f "tokens=1-5*" %%1 in ('vol') do (
set vol=%%6 & goto done
)
:done
echo %vol%
vol命令将为您提供MS SHELL中的卷名称