windows - 如何读取批处理文件中驱动器或卷的标签?

标签 windows batch-file

我正在尝试编写一个批处理文件来将我的 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

关于windows - 如何读取批处理文件中驱动器或卷的标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8649934/

相关文章:

c++ - 如何为 Win32 应用程序设置任务栏图标?

linux - 对 AIX 和批处理文件的理解和澄清

windows - 停止/启动服务 - 处理 STOP_PENDING 和 START_PENDING

windows - 处理 Windows 批处理脚本中的引号

windows - 无法从简单批处理中删除文件

windows - 在bat中ctrl+c后更改当前目录

python - Cython 安装问题

python - 安装mysql-python时"Cannot open include file: ' config-win.h ': No such file or directory"

无法使用 MinGW 编译 C 代码

c++ - 为什么 FFMPEG 录屏视频速度快?