GB级别显示2.31GB这样的数字;MB级别显示23MB这样的数字;MB以下显示0MB- @echo oFF
-
- for /f "delims=" %%a in ('dir /a-d/s/b') do (
- call :calc_size %%~za size
- setlocal enabledelayedexpansion
- echo;%%a !size!
- endlocal
- )
-
- pause&exit
- :calc_size
- setlocal&set "var=%1"
- set "var=%var:~,-6%"
- if not "%var%"=="" set/a "GB=%var%>>10"&set/a "MB=%var%%%(1<<10)"
- if "%MB%"=="" set "var=0 MB"&goto:end
- if "%GB%"=="0" set "var=%MB% MB"&goto:end
- if "%MB:~1%"=="" set "MB=0%MB%"
- if "%MB:~2%"=="" set "MB=0%MB%"
- set "var=%GB%.%MB:~,2% GB"
- :end
- endlocal&set "%2=%var%"&goto:eof
复制代码
|