How to delete files older than n days with additional condition?

For needs backup archive need to come up with an algorithm that after creating the directory archive would leave 5 latest created directories with archives. An additional condition is to remove directories older than 14 days. Ie in the directory can be more than 5 directories if they are created, for example, in one day.
Method delete all the directories except the last 5 are not satisfied, because during the day can be created in 5 to 7 backups.
Method delete all older than 14 days is not suitable because can not create new backups more than 14 days.
So you need to combine these two methods into one.
Can anyone help with a solution to this problem?
April 7th 20 at 15:37
1 answer
April 7th 20 at 15:39
Premires through all the directories for each get command dir /ad /tc creation date of the directory. Next, using calculate how much time has passed since sozdaniya directory and decide to delete or not.

Find more questions by tags cmd/batDOS