【发布时间】:2013-03-01 12:38:30
【问题描述】:
相关:How to get the most recent file using a batch script in windows
我想使用 Windows 批处理脚本从目录中复制最新的 2 个文件。
【问题讨论】:
标签: windows batch-file
相关:How to get the most recent file using a batch script in windows
我想使用 Windows 批处理脚本从目录中复制最新的 2 个文件。
【问题讨论】:
标签: windows batch-file
@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
【讨论】:
我的版本基于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
【讨论】: