I want to delete all the folders from a directory except the 2 most recently updated folders (Last modified date).
I want to do this using the command line. How do I do it?
Below is the code to display folders sorted by last modified time:
dir /ad-h /od
I tried using FOR /D
command:
for /d "skip=2 tokens=*" %G in ("dir /ad-h /od") DO echo going to delete %G
But I get the below error message:
"skip=2 tokens=*" was unexpected at this time.
How do I do it?