简体   繁体   中英

Copying a file based on last modified date in batch file

假设我的服务器在1.30处生成一个文件,直到2.30它将仅写入相同的文件,而2.31它将创建另一个文件,因此,如果我在2.40运行此批处理文件以将数据从1.30转换为2.30,我需要生成的文件1.30不是2.31

@echo off

set enabledelayedexpansion
set /A counter=0

for /f %%f in ('dir /b /o:-d ^| find ^"file-mask^"') do (
set /A counter=!counter!+1
    if !counter! EQU 2 (
        copy %%f file2 /Y
        goto :endloop
    )
)
:endloop
endlocal

This will copy the second "last created" file.You can change the location where it will be copied and file mask.Check also robocopy and forfiles commands .Especialy robocopy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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