【问题标题】:Need to identify if two log files have a different timestamp需要识别两个日志文件是否有不同的时间戳
【发布时间】:2015-03-20 11:06:03
【问题描述】:

我希望检查两个日志文件(Windows 操作系统)的时间戳,如果它们不同,我想向我们的支持电子邮件发送一封电子邮件。任何意见将是有益的。我对批处理命令有相当的了解,但不是专家。

【问题讨论】:

    标签: file batch-file logging timestamp


    【解决方案1】:
    @echo off
        setlocal enableextensions disabledelayedexpansion
    
        set "file1=c:\somewhere\file1.log"
        set "file2=c:\otherplace\file2.log"
    
        set "sameFileCount=0"
        for /f %%a in ('
            xcopy /d /l /y "%file1%" "%file2%" ^& xcopy /d /l /y "%file2%" "%file1%"
        ') do if "%%a"=="0" set /a "sameFileCount+=1"
    
        if not %sameFileCount%==2 (
            echo Files have different timestamps
            rem Your mail command here
        )
    

    这将执行两个 xcopy 命令来复制 file1 到 file2 和 file2 到 file1,但是

    • /l 开关将使命令“模拟”操作,仅获取将被复制的文件列表,但不复制任何内容。
    • /d 开关表示只有在文件戳不同时才应执行“复制”操作。

    如果两个命令都没有指示必须复制文件(它们指示要复制 0 个文件),则文件具有相同的时间戳。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-10
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多