[模块分享] 功能:把字节转换成MB或者GB形式
很多命令获得的文件或分区\硬盘大小以Byte表示
看起来诸多不便,故此转换成MB或者GB形式:
-
- @echo off
- setlocal enabledelayedexpansion&cls
- ::==============================================================
- call:Getsize "104864059392"
- echo %Getsize%
- ::==============================================================
- :end
- ENDLOCAL&echo 按任意键退出&pause>nul
- ::=======================MODE CODE==============================
- :Getsize
- ::批处理能处理的最大数为[2,147,483,647]即4Byte31Bit,第32位表示正负符号
- ::1MB=1024KB=1,048,576 Byte
- ::1GB=1048576*1024=1,073,741,824 Byte 1073741824*2=2147483648
- ::Integer 整数;Decimal 小数
- set "Size_Num=%~1"
- set "dd="
- set /a dd=%Size_Num% "-" 2147483647
- if %errorlevel%==9168 (
- set /a GetSize=!Size_Num:~-9! "/" 1024 "/" 1024 "*" 100 "/" 1024
- set /a GetSize=!Size_Num:~0,-9!000000 "/" 1024 "*" 1000 "/" 1024 "*" 100 "/" 1024 "+" !GetSize!
- set "GetSize=!GetSize:~0,-2!.!GetSize:~-2! GB"
- goto:eof
- )
- if not "%dd%"=="" (
- echo %dd%
- if %dd% GTR 0 (
- set /a GetSize=%dd% "/" 1024 "/" 1024 "*" 100 "/" 1024
- set /a GetSize=200 "+" !GetSize!
- set "GetSize=!GetSize:~0,-2!.!GetSize:~-2! GB"
- goto:eof)
- if %Size_Num% GEQ 1073741824 (
- set /a GetSize=%Size_Num% "/" 1024 "/" 1024 "*" 100 "/" 1024
- set "GetSize=!GetSize:~0,-2!.!GetSize:~-2! GB"
- ) else (
- set /a GetSize=%Size_Num% "/" 1024 "*" 100 "/" 1024
- set "GetSize=!GetSize:~0,-2!.!GetSize:~-2! MB"
- )
- )
- goto:eof
- ::=======================END CODE===============================
复制代码
|