Answer the question
In order to leave comments, you need to log in
How to delete files older than n days with add. condition?
For the needs of backup archiving, you need to come up with an algorithm that, after creating a directory with an archive, would leave the last 5 created directories with archives. Additional condition - delete directories ONLY older than 14 days. That is, a directory can contain more than 5 directories if they were created, for example, on the same day.
The method of deleting all directories except the last 5 does not suit, because 5 - 7 backups can be created during the day.
The method of removing all older than 14 days is not suitable because new backups may not be created for more than 14 days.
Therefore, you need to combine these two methods into one.
Answer the question
In order to leave comments, you need to log in
You loop through all the directories for each and get the directory creation date with the dir /ad /tc command. Then using https://ss64.com/nt/syntax-datemath.html you calculate how much time has passed since the directory was created and decide whether to delete it or not.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question