本文介绍了使用WMIC获取驱动器空间信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图让物理驱动器的信息与WMIC计算机得到的东西是这样的:
I'm trying to get info of the physical drives in a computer with wmic to get something like this:
Drive C:
500 GB Total
100 GB Free
20% Free
Drive D:
500 GB Total
100 GB Free
20% Free
我的code到目前为止是:
My code so far is:
for /f "usebackq tokens=*" %%a in (`wmic logicaldisk where "drivetype=3" get caption`) do (
echo "Drive=%%a"
for /f "usebackq delims== tokens=2" %%x in (`wmic logicaldisk where DeviceID='%%a'"
get FreeSpace /format:value`) do set FreeSpace=%%x
for /f "usebackq delims== tokens=2" %%x in (`wmic logicaldisk where "DeviceID='%%a'" get Size /format:value`) do set Size=%%x
echo FreeMB=%FreeSpace%
echo SizeMB=%Size%
set /a Percentage=100 * %FreeSpace% / %Size%
echo %%a is %Percentage% %% free
)
和我的输出是:
"Drive=Caption
No Instance(s) Available.
No Instance(s) Available.
FreeMB=9193357312
SizeMB=80024170496
Invalid number. Numbers are limited to 32-bits of precision.
is % free
"Drive=C:
No Instance(s) Available.
No Instance(s) Available.
FreeMB=9193357312
SizeMB=80024170496
Invalid number. Numbers are limited to 32-bits of precision.
is % free
"Drive=E:
No Instance(s) Available.
No Instance(s) Available.
FreeMB=9193357312
SizeMB=80024170496
Invalid number. Numbers are limited to 32-bits of precision.
is % free
"Drive=
No Instance(s) Available.
No Instance(s) Available.
FreeMB=9193357312
SizeMB=80024170496
Invalid number. Numbers are limited to 32-bits of precision.
is % free
我得到了许多行甚至不具有一个驱动器,我无法格式化的价值,所以我可以计算百分比,或者在正常的格式显示值
I'm getting to many lines that don't even have a drive and I can't format the value so I can calculate the percentage, or show the values in a normal format
推荐答案
这可能会为你工作:code是在您的批处理文件的底部加入,并且使用
This may work for you: the code is to be added at the bottom of your batch file, and use
电话:HDD-信息
在code中显示的数据。
in your code to display the data.
goto :eof
:code by aGerman - display drive stats and bar graph (REMmed out)
:hdd-info
@echo off &setlocal
set "GB=1073741824"
for /f "skip=1 delims=" %%i in ('wmic logicaldisk get DeviceID^,FreeSpace^,Size') do (
for /f "tokens=1-3" %%j in ("%%i") do call :output %%j %%k %%l
)
goto :eof
:output
if "%3"=="" (
rem echo Unable to discover the drive properties.
goto :eof
)
for /f "tokens=1-4" %%i in (
'mshta vbscript:Execute("CreateObject(""Scripting.FileSystemObject"").GetStandardStream(1).Write(FormatNumber(%3/%GB%, 2) & "" "" & FormatNumber((%3-%2)/%GB%, 2) & "" "" & FormatNumber(%2/%GB%, 2) & "" "" & Round((%3-%2)*50/%3)):Close"^)'
) do (
set "size= %%i"
set "used= %%j"
set "free= %%k"
set /a "nUsed=%%l, nFree=50-%%l"
)
echo(
echo %1
echo Size: %size:~-10% GB
echo Used: %used:~-10% GB
echo Free: %free:~-10% GB
:: echo(
:: for /l %%i in (1 1 %nUsed%) do <nul set /p "=▒"
:: for /l %%i in (1 1 %nFree%) do <nul set /p "=█"
:: echo(&echo(&echo(
goto :eof
这篇关于使用WMIC获取驱动器空间信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!