I am trying to create a 1 line command that will get all directories matching a pattern and delete a certain number of them.
Lets say i have a directory like this:
C:/
tmp/
www/
01/
02/
03/
04/
05/
And i want to only keep the latest 2 folders 05
and 04
.
i have a for loop that will output all the folders, the part im having trouble with is counting past a certain amount:
> for /f "tokens=*" %G in ('dir /b /a:d "C:\tmp\www\*"') do echo Found %G
Found 20161201004853
Found 20161201005125
Found 20161201005246
I have tried adding in a counter but im not sure how to separate the commands since its all on 1 line. Despite a large amount of googling for how, im hoping someone here know.
As always if there is a better way to do this I am open to that too.