Double conditional – delete all folders older than 3 days but keep a minimum of 10

Question:

I have a bit of problem I can’t seem overcome. I have a folder with a lot of folders that are generated. I want to delete all folders that are older than three days, but I want to keep a minimum of 10 folders.

I came up with this half-working code and I’d like some suggestions how to tackle this.

Answer:

You just have to filter your list of files older than 3 days:

Leave a Reply