FOR /F "skip=5 delims=" %%G IN ('dir /b /O-D /A-D') DO del "%%G"
Will delete all files except the 5 newest ones. I couldn't find a one-liner to keep all files newer than 5 days so for that you might have to use some more complicated logic.
/b
Lists only file names without extra info
/O-D
Sorts list by reverse date order.
/A-D
Filters to only show non-directory files
skip=5
skips the 5 first lines (5 newest ones).
and put the command into a schedule
Will delete all files except the 5 newest ones. I couldn't find a one-liner to keep all files newer than 5 days so for that you might have to use some more complicated logic.
/b
Lists only file names without extra info
/O-D
Sorts list by reverse date order.
/A-D
Filters to only show non-directory files
skip=5
skips the 5 first lines (5 newest ones).
and put the command into a schedule