本帖最后由 77七 于 2024-8-28 13:32 编辑
回复 18# walkercolin
代码中的计算方式是terse大佬的代码,我数学不好,认真看,还是存在数学问题上的鸿沟,即使数学老师在,我估计也要学习很久,所以不想了,只是从for /l 字符串截取不为空的前提下,改动了一下 计算长度,和 for /l 中的结尾数字,不一定对,请多包涵。
- @echo off
- rem 保存为ansi编码
- cd /d "%~dp0"
- rem 排除特定文件(000,00.1,00.2,00.3),不需要可以删除下一行
- set "_f=^|findstr /rvix /c:"00\.[123]\.[jpb][pnm][gp]" /c:"000\.[jpb][pnm][gp]""
-
- (for /f "delims=" %%d in ('dir /b /ad') do (
- setlocal
- pushd "%%d"
- if not errorlevel 1 (
- for /f %%a in ('dir /b /a-d *.jpg *.png *.bmp %_f% ^|find /c /v ""') do (
- set /a "1/%%a" && set P=%%aP
- )
- for /f %%a in ('dir /b /a-d *.mp4 *.avi *.mov *.mkv ^|find /c /v ""') do (
- set /a "1/%%a" && set V=%%aV
- )
- set m=1048576
- for /f "eol=0tokens=3" %%j in ('dir /s /a-d /-c *.jpg *.png *.bmp *.mp4 *.avi *.mov *.mkv 2^>nul^| findstr /i "个文件.*字节$"') do (
- set size=%%j00
- setlocal enabledelayedexpansion
- if !size! geq 102400 (
- if !size! geq 104857600 (
- set s=MB
- set t=!size!
- set len=!t:~9!9876543210
- set /a len=!len:~9,1!+9
- set /a "r=!t:~,8!%%m,size=!t:~,8!/m"
- set /a len-=1
- for /l %%j in (8 1 !len!) do (
- set/a "q=!r!!t:~%%j,1!/m,r=!r!!t:~%%j,1!%%m"
- set "size=!size!!q!"
- )
- if !size! geq 102400 set s=GB&set /asize/=1024
- ) else set s=KB&set /asize/=1024
- ) else set s=Byte
- for /f "tokens=1-3" %%a in ("!size:~,-2! !size:~-2! !s!") do (
- endlocal
- set Z=%%a.%%b%%c
- )
- )
- popd
- if defined Z (
- call echo ren "%%d" "%%d [%%p%%%%V%%-%%Z%%]"
- )
- )
- endlocal
- )) 2>nul
- pause
复制代码
|