繁体   English   中英

如何将10个最新文件批量复制到Windows中的目录?

[英]How to batch-copy the 10 newest files to a directory in Windows?

我使用以下脚本将最新的360个文件(一年定期备份)保留在目录中:

for /f "skip=360 eol=: delims=" %%F in ('dir /b /o-d /a-d *.*') do @del "%%F"

之后如何将最新的7个文件复制到另一个目录?

@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" x:\somewehere
        )
    )

    rem Pure arithmetics 2 - No negation operator
    set "numFiles=7"
    for /f "delims=" %%a in ('dir /b /o-d /a-d') do (
        2>nul set /a "1/numFiles", "numFiles-=1" && (
            echo copy "%%~fa" x:\somewehere
        )
    )

    rem Number list of files
    set "numFiles=7"
    for /f "tokens=1,* delims=:" %%a in ('
        dir /b /o-d /a-d
        ^| findstr /n "^"
    ') do if %%a leq %numFiles% (
        echo copy "%%~fb" x:\somewehere
    )

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM