@echo %date% @Set Year=%date:~10,4% @Set Month=%date:~4,2% @Set Day=%date:~7,2% @Set CurrentDate=%Year%_%Month%_%Day% @set BaseDir=D:temp echo %CurrentDate% rem 删除%BaseDir% 下的子目录,除了 %CurrentDate% 这个子目录 for /f %%i in ('dir /b /ad %BaseDir% ^| findstr /i /v "%CurrentDate%" ') do rd /s /q "%BaseDir%\%%i"