我需要创建一个批处理脚本,持续监视特定文件的更改,在本例中为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)