On Windows, I need to delete subfolders when there are more than 5 in a folder. But only if they have been created more then 30 days ago. Otherwise I just need to keep 5 folders.
Folder subfolder1 : created December 25 - to delete subfolder2 : created February 1 - to keep subfolder3 : created February 1 - to keep subfolder4 : created February 2- to keep subfolder5 : created February 3- to keep subfolder6 : created February 3- to keep subfolder7 : created February 3- to keep ... subfolder45 : created February 12 - to keep subfolder46 : created February 13 - to keep
Folder subfolder1 : created December 10 - to keep subfolder2 : created December 25 - to keep
What I have so far is :
FORFILES /p C:\CMQDev\Build\CMQWin-DB -D -30 -C "CMD /C IF @ISDIR==TRUE ECHO rd /q /s @FILE&rd /q /s @FILE"
And I can count the number of folders with :
dir /b | find /c /v