How to batch-copy the 10 newest files to a directory in Windows?
问题 I use the following script to keep only the newest 360 files (a year, daily-made backup) in the directory: for /f "skip=360 eol=: delims=" %%F in ('dir /b /o-d /a-d *.*') do @del "%%F" How to afterwards copy the newest 7 files to another directory? 回答1: @echo off setlocal enableextensions disabledelayedexpansion rem Three alternatives rem Pure arithmetics set "numFiles=7" for /f "delims=" %%a in ('dir /b /o-d /a-d') do ( 2>nul set /a "1/numFiles", "numFiles-=!!numFiles" && ( echo copy "%%~fa"