delete all but X most recent folders

前端 未结 1 1167
梦如初夏
梦如初夏 2021-01-21 07:34

Can someone provide a batch script that will delete all but the X most recently modified folders in a directory. I\'ve looked at How do I delete old files from a directory while

1条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-21 08:29

    This will keep the 10 latest log files based on modification date:

    @echo off
    for /f "skip=10 delims=" %%a in (' dir *.log /o-d /a-d /b ') do echo del "%%a"
    

    Remove the echo to make it perform the deletions rather than just display them.

    0 讨论(0)
提交回复
热议问题