
[已解決]以MB顯示容量的批處理是怎樣避免超出set/a的計(jì)算范圍最后由 pcl_test 于 -12-7 21:51在以兆顯示容量的大小時碰到一下情況在網(wǎng)上搜了一下了,說DOS計(jì)算有范圍的?,F(xiàn)在硬盤的容量都很大,基本上以字節(jié)來計(jì)算,都超過了DOS的計(jì)算范圍。在論壇找到一下代碼
- @echo off
- setlocal enabledelayedexpansion
- set /a num2=1024*1024
- set total=0
- for %%i in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
- set num1=0
- set num3_str=
- set num4=
- for /f tokens=3 %%j in ('dir /-c %%i: 2^>nul') do (
- set num1=%%j
- )
- if not !num1!==0 (
- call :loop
- for /f delims=0 tokens=* %%k in (!num3_str!) do (
- set num3_str=%%k
- )
- echo.
- echo %%i 盤剩余空間為 !num3_str! MB
- set /a total+=!num3_str!
- echo.
- )
- )
- echo 剩余空間總量為 !total! MB
- pause
- goto :eof
- :loop
- :: 求商
- set /a num3=%num4%%num1:~0,1%/%num2%
- :: 求商序列
- set num3_str=%num3_str%%num3%
- :: 求余
- set /a num4=%num4%%num1:~0,1%%%%num2%
- if %num4% equ 0 (
- set num4=
- )
- set num1=%num1:~1%
- if not %num1%== (
- goto :loop
- )
- goto :eof
nclick="copycode($('code0'));">復(fù)制代碼
確實(shí)可以實(shí)現(xiàn),以兆顯示容量但是卻不是用的什么原理,避免了DOS的計(jì)算范圍?