我来贴个 即使纯p也不用这么复杂吧- @echo off
- set /p p="请选择要计算的目录类型,1是只取第一层目录,2是递归当前目录,默认是第一层目录"
- if %p% equ 2 (set "_dir=dir /ad/b/s^|sort /r") else set "_dir=dir /ad/b"
- setlocal enabledelayedexpansion
- set l=00000000&for /l %%i in (1 1 2) do set "l=!l!!l!"
- endlocal&set l=%l%
- set "var=64 32 16"
- set /amd=1048576,w=32,len=0
- set "mdl=%l:~9%%md%00"
- for /f "delims=" %%a in ('%_dir%') do (
- set "fullname=%%a"&set "name=%%~nxa"
- setlocal enabledelayedexpansion
- for %%i in ("!fullname!\*") do set "size=%%~zi00"
- set "s=!l!!size!"
- if "!s:~-%w%!" geq "!mdl!" (
- set "s=!size!"
- if "!s:~16!" neq "" set len=16&set "S=!S:~16!"
- set s=!s!FEDCBA9876543210&set/a "Len+=0x!s:~16,1!"
- set/a "remainder=!Size:~,8!%%Md,GKB=!Size:~,8!/Md"
- for /l %%i in (8 1 !Len!) do (
- set/a "quotient=!remainder!!Size:~%%i,1!/Md,remainder=!remainder!!size:~%%i,1!%%Md"
- set "GKB=!GKB!!quotient!"
- )
- if !GKB! geq 102400 (
- set /a GKB/=1024
- IF !GKB! GEQ 102400 (
- set /a GKB=!GKB!/1024
- set GKB=!GKB:~,-2!.!GKB:~-2! TB--
- ) else set GKB=!GKB:~,-2!.!GKB:~-2! GB--
- )else set GKB=!GKB:~,-2!.!GKB:~-2! MB--
- ) else if !size! geq 102400 (
- set /a GKB=!size!/1024
- set GKB=!GKB:~,-2!.!!GKB:~-2! KB--
- ) else if !size! geq 1024 (
- set /a GKB=!size!/1024
- set GKB=0.!GKB! KB--
- ) else set GKB=!size:~,-2! Byte--
- ren "!fullname!" "!GKB!!name!"
- endlocal
- )
- pause
复制代码
|