file - 如何使用批处理检测 .txt 文件中的更改?

标签 file batch-file updates

我制作了一个简单的局域网聊天批处理文件,我想知道是否 有一个命令可以检查特定的 txt 文件是否已更新。 聊天历史记录存储在 log.dat 中,我希望在有新消息时有声音通知或类似的东西。

@echo off
title LAN chat reader
call Color.bat

:read
call Color.bat
cls
type log.dat
timeout /t 3 /nobreak >nul
goto read

(我是菜鸟,请告诉我这是否可能)

最佳答案

要检查文件日期/时间,请使用 for%%~t 前缀:

@echo off
title LAN chat reader
setlocal enableDelayedExpansion

:read
    call Color.bat
    cls
    type log.dat

    for %%a in (log.dat) do set filetimesize=%%~tza
    :checkupdate
        ping -n 1 -w 100 localhost >nul
        for %%a in (log.dat) do if "!filetimesize!"=="%%~tza" goto checkupdate
    echo updated
    goto read

关于file - 如何使用批处理检测 .txt 文件中的更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32895172/

相关文章:

android-studio - Android Studio更新(1.5至2.2.3)中断了项目

java - 迭代目录中的大量文件

python 写入 CD/DVD iso 文件

c - 如何链接多个 .c 文件

batch-file - 当文件名与模式匹配时批处理脚本删除文件

c++ - Protocol Buffer 可以部分更新吗?

javascript - 从文件中读取并查找特定行

windows - 批处理文件以将文件夹移动并重命名为相对路径

c - 在 C 程序中打开批处理文件 (.bat)?

更新 macOS 后 Xcode 更新卡住