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 G
wmic LogicalDisk where "DeviceID='C:' " Get Size
This may work for you: the code is to be added at the bottom of your batch file, and use
call :hdd-info
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
As the errormessage tells you, set
is limited to 32-bit-integers. If you can live with an accuracy of MB
, you can shorten the numbers like this:
set SizeMB=%size:~0,-6%
(it takes the string except the last 6 characters)
It may be not quite correct in a mathematic sense, but should be good enough.
Of course you will have to shorten %freeMB%
the same way.