How can I convert this raw bytes output to GB?

前端 未结 5 1905
陌清茗
陌清茗 2020-12-21 07:08

I\'m using the below code to output the current free space on the C: Drive. How can I convert the output from bytes to GB using batch?

@echo off
for /f \"use         


        
5条回答
  •  有刺的猬
    2020-12-21 07:50

    REM ECHO Disk Storage
    
    for /f "tokens=1" %%d in (
     'wmic logicaldisk where drivetype^=3 get deviceid ^| find ":"') do ( 
        for /f "usebackq delims== tokens=2" %%x in (`wmic logicaldisk where "DeviceID='%%d'" get Size /value`) do set Size=%%x
        echo VolumeSize on %%d Partition = !Size:~0,-10!,!Size:~2,-8! GB >output.txt
        for /f "usebackq delims== tokens=2" %%x in (`wmic logicaldisk where "DeviceID='%%d'" get FreeSpace /value`) do set FreeSpace=%%x
        echo Freespace on %%d Partition = !FreeSpace:~0,-10!,!FreeSpace:~2,-8! GB >> output.txt
        echo.
        )
    )
    

提交回复
热议问题