Windows 批处理:为 FOR 循环设置变量,WMIC 磁盘驱动器获取大小

Windows Batch: Set variables for FOR loop, WMIC diskdrive get size

下面提到的批处理文件显示PC的硬盘大小,但是如果PC中安装了1个以上的硬盘,那么在这种情况下如何设置变量?怎么做?

set _hdd=
For /F "Skip=1 Delims=" %%A In (
    '"WMIC diskdrive Where (MediaType="Fixed hard disk media") Get Size"'  
) Do For /F "Tokens=1-2" %%B In ("%%A") Do set _hdd=%%B
Echo %_hh%
pause
@Echo off&SetLocal EnableExtensions EnableDelayedExpansion
set cnt=0
For /F "Skip=1 Delims=" %%A In (
    '"WMIC diskdrive Where (MediaType="Fixed hard disk media") Get Size"'  
) Do For /F "Tokens=1-2" %%B In ("%%A") Do (
  Set /A cnt+=1
  set _hdd[!cnt!]=%%B
)
Set _hdd[
pause

示例输出:

> Q:\Test17-03\SO_42530497.cmd
_hdd[1]=2000396321280
_hdd[2]=256052966400

类似于我的上一个答案和已经提供的回复:

@Echo Off
For /F "Skip=1 Delims=" %%A In (
    '"WMIC DiskDrive Where (MediaType Like 'Fixed%%') Get Index, Size"'
) Do For /F "Tokens=1-2" %%B In ("%%A") Do Set "HD%%B=%%C"
Set HD
Timeout -1