- @echo off
- set /p n=保留数量:
- setlocal enabledelayedexpansion
- for /f "delims=" %%i in ('dir /b /s /a-d ^|find /v "%~0"') do (
- for /f "tokens=1-3 delims=." %%a in ("%%~nxi") do (
- set m=00000%%c
- if "%%c" equ "" (
- set "#!m:~-5!#%%~nxi.0=%%i"
- ) else (
- set "#!m:~-5!#%%~nxi=%%i"
- )
- )
- )
- for /f "tokens=1-4* delims=#=." %%a in ('set # ^|sort /r') do (
- if defined _"%%b.%%c" (
- set m=!_"%%b.%%c"!
- set /a m+=1
- set _"%%b.%%c"=!m!
- ) else set _"%%b.%%c"=1
- if !_"%%b.%%c"! gtr %n% (
- rem 显示正确则去掉 echo 再执行
- echo del "%%e"
- )
- )
- endlocal
- pause
复制代码
|