That additional info raises further questions.
1. How often do you run the script?
2. How often are new folders created? Daily? Weekends as well?
If it's always one folder a day, even on weekends, and you run the batch daily, you can just tell it to delete the folder from 4 days ago.
Otherwise you'll need to program some logic in there.
One example can be found at the bottom here where you create an array of all folders available and add the three latest ones to the exclusion list:
Why overcomplicate things? Can you just delete files and folders older than X days ?
FORFILES /P C:\MyPath\ /S /M log*.xml /D -30 /C "cmd /c del @file"
/S – look at subdirectories
log*.xml – that is the file pattern, you could have it be like *.txt for example
/D -30 = files greater than 30 days
/C – thats the command you want to run
this is pretty much a one line command that could replace a ton of vbScripts, batch files, and other apps I have seen over the years to clean up files. Something for every sys admin’s toolbelt.
I have tried the following comments in a batch file,
robocopy c:\logs\SoManyDirectoriesToDelete\ c:\temp\OldDirectoriesGoHere\ /move /minage:3
rmdir /s /q c:\temp\OldDirectoriesGoHere
but the problem with the above script is that all the files got deleted irrespective of the time span,I need to remove the files which are older than 3 days only
In my case the new files get added daily,so I need to execuit the batch file daily to remove the older once