Page 1 of 1

wmic, overall disk capacity, convert bytes to gb

Posted: 24 Oct 2018 13:35
by BoQsc
Here is a problem:
When a single USB is connected, the device capacity in gigabytes are calculated correctly.
But, when I tried to connect one more USB flash drive, the newly connected flash drive's capacity is displayed incorrectly. (way bigger)
Is this weird only for me?

Code: Select all

@echo off
setlocal enabledelayedexpansion


:: https://superuser.com/questions/1192107/wmic-output-property-value-without-property-name/1192171#1192171
for /f "tokens=* skip=1" %%a in ('"wmic diskdrive where(InterfaceType="USB") get Size | findstr ".""') do (

set "size="
set "bytes="
set "kb="
set "mb="
set "gb="

set "size=%%a"
set "bytes=!size:~0,-4!"
set /a kb = bytes/1024
set /a mb = kb*100/1024
set /a gb = mb/1024
set /a gb = !gb:~0,-1! 
echo !gb!GB
:: Output 
:: 19GB (actually 7GB USB)
:: 14GB (this one correct)

)





pause

Re: wmic, overall disk capacity, convert bytes to gb

Posted: 26 Oct 2018 03:43
by penpen
Are the sizes of your usb devices correctly displayed by wmic:

Code: Select all

wmic diskdrive where(InterfaceType="USB") get Size
If the sizes are OK, then it would help, if your wmic-statement output.


penpen