hope you can help me. I am looking for a way to use batchscript to delete all folders in a subfolder except
- the very newest folder AND
- a special folder named "BACKUP".
So the backup folder can be older, but it needs to be kept. All other folders except the one with the newest date should be deleted.
There will be files in all of those folders, but there are no hidden files or subfolders, so this needs not to be considered in this case.
I found a lot of solutions here to either spare the backup folder or delete everything except the newest, but I cannot seem to find a solution that can do both.
for /d %%i in ("C:\Parent\*") do if /i not "%%~nxi"=="BACKUP" del /s /q "%%i"
I.e. like this, but it will not keep the newest folder. All the other folders except the backup folder have names like "20220215" "20210405".
Thank you for any help you can give.
KR Susanne