例えば、日付が名前についたフォルダを2世代だけ残したい時に使えるかと思います。
@echo off
setlocal
dir /B 2024* > list.txt
set "list_file=list.txt"
set "count=0"
for /f "delims=" %%a in ('type "%list_file%"') do (
set /a count+=1
)
echo. List_Count: %count%
if %count% geq 3 (
call :Sub1
) else (
exit /b
)
exit /b
:Sub1
for /f "tokens=*" %%i in (list.txt) do (
echo Processing: %%i
rd /s /q %%i
goto :end
)
:end
endlocal
