问题描述
我正在尝试获取所有本地磁盘的型号和大小。
我想为每个磁盘在一行上输出。
示例:型号三星大小500GB
I am trying to get Model and Size of all local disks.
I want to output on one line for each disk.
Example: Model Samsung Size 500GB
@echo off
for /f "tokens=2 delims==" %%d in ('wmic diskdrive get Model,Size /value') do (
set Model=%%d
set Size=%%d
)
echo Model %Model% Size %Size%
pause
但是什么也没有。
推荐答案
由于模型描述中可能包含空格,因此您需要将输出格式设置为 csv
,因此输出应以逗号分隔(我希望不要包含逗号的模型描述-到目前为止我还没有看到)。
As model descriptions may contain spaces, you need to format the output as csv
, so the output is delimited by commas (I hope there aren't model descriptions that contain commas - I didn't see one so far).
没有 / value
的每个磁盘是列在一行(节点,模型,大小
)中,因此您需要 tokens = 2,3
。添加 skip = 2
删除标题行并将固定的字符串添加到最终输出中:
Without /value
each disk is listed in one line (Node,Model,Size
), so you need tokens=2,3
. Add a skip=2
to remove the header line and add your fixed strings to the final output:
for /f "skip=2 tokens=2,3 delims=," %%a in ('"wmic diskdrive get Model,Size /format:csv"') do @echo Model %%a Size %%b
这篇关于一行获取命令提示符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!