CODE: [Copy to clipboard]
@echo off
title delete old folder when great 30 by james168
xcopy /s /q SRC X:\temp
for /f "skip=5 tokens=1,2 delims= " %%a in ('dir /ad /ogd X:\temp') do (
if "%%b"=="个目录" set TOTAL=%%a
)
if %TOTAL% leq 32 goto notdel
set /a GRT=%TOTAL%-32
set NUM=0
for /f "tokens=1 delims= " %%j in ('dir /ad /ogd /b') do (call :dd1 "%%j")
goto end
:notdel
echo.
echo Folder less than 30
goto end
:end
echo Press any key exit
pause>nul
exit
:dd1
set /a NUM+=1
if %NUM% leq %GRT% (rd /q /s X:\temp\%1)
goto :eof
[