windows 如何多次查询分区名(标签)并将其保存在变量中?

gcuhipw9  于 2023-06-07  发布在  Windows
关注(0)|答案(1)|浏览(217)

我需要在几个地方读出分区名称(标签),并使用Windows 10批处理文件将它们存储在变量中。只有在第一次使用以下代码时才有效:

set "DriveLetter=M:"
for /f "tokens=2 delims==" %%a in ('wmic volume where DriveLetter^="%DriveLetter%" get Label /value') do (
    set "DriveLabel=%%a"
)
echo DriveLabel   =   %DriveLabel%
pause

每次我再次使用wmic命令时,都会收到错误消息:
没有可用的示例。
我读过:How to run wmic command in a batch file
但是我的知识太贫乏了,所以我不能为我的问题编写一个工作代码。

**提示:**我需要多次读出分区名(标签),并存储在变量中。它不能用wmic volume ...DriveLetter来完成。

amrnrhlw

amrnrhlw1#

多次阅读变量中的标签的示例:

set "DriveLetter=M:"
for /f "tokens=2 delims==" %%a in ('wmic volume where DriveLetter^="%DriveLetter%" get Label /value') do (
  set "DriveLabel=%%a"
)
echo DriveLabel   =   %DriveLabel%
…
Several other commands
…
set "DriveLetter=H:"
for /f "tokens=2 delims==" %%a in ('wmic volume where DriveLetter^="%DriveLetter%" get Label /value') do (
  set "DriveLabel=%%a"
)
echo DriveLabel   =   %DriveLabel%
…
Several other commands
…
set "DriveLetter=U:"
for /f "tokens=2 delims==" %%a in ('wmic volume where DriveLetter^="%DriveLetter%" get Label /value') do (
  set "DriveLabel=%%a"
)
echo DriveLabel   =   %DriveLabel%
…
Several other commands
…

相关问题