使用Windows批处理脚本复制最新的2个文件

时间:2013-03-13 14:09:23

标签: windows batch-file

相关:How to get the most recent file using a batch script in windows

我想使用Windows批处理脚本从目录中复制最新的2个文件。

2 个答案:

答案 0 :(得分:1)

@ECHO OFF
SETLOCAL
SET transfer=xx
FOR /f "delims=" %%i IN ('dir/b/a-d/o-d *.*') DO IF DEFINED transfer CALL SET transfer=%%transfer:~1%%&ECHO %%i

只需将TRANSFER设置为#transfers的执行长度;显然用适当的COPY命令替换echo %%i

答案 1 :(得分:0)

我的版本基于Peter Wright的答案......

@ECHO OFF
setlocal EnableDelayedExpansion
set j=0

FOR /f "delims=" %%i IN ('dir /b /a-d /o-d *.*') DO (
    echo %%i
    set /A j=j+1
    if !j! geq 2 (
        goto :end
    )
)
:end