小编Jam*_*Mry的帖子

监视文件更改的批处理脚本

我需要创建一个批处理脚本,持续监视特定文件的更改,在本例中为LogTest.txt.

文件更新后,它将触发一个VBScript消息框,显示LogTest.txt中的最后一行.这个想法是,在消息框被清除后,这将继续监控.

我尝试过使用该forfiles选项,但这只能让我处理日期而不是时间.我知道PowerShell和其他选项都可用,但由于原因太长而无法解释,我只能使用批处理和VBScript.

批处理文件:

@echo off

:RENEW

forfiles /m LogTest.txt /d 0
if %errorlevel% == 0 (
  echo The file was modified today
  forfiles /M LogTest.txt /C "cmd /c echo @file @fdate @ftime"
  cscript MessageBox.vbs "Error found."
  REM do whatever else you need to do
) else (
  echo The file has not been modified today
  dir /T:W LogTest.txt
  REM do whatever else you need to do
)

goto :RENEW     
Run Code Online (Sandbox Code Playgroud)

MessageBox.vbs:

Set objArgs = WScript.Arguments
messageText = …
Run Code Online (Sandbox Code Playgroud)

vbscript file batch-file monitor

1
推荐指数
1
解决办法
4537
查看次数

标签 统计

batch-file ×1

file ×1

monitor ×1

vbscript ×1