连续检查已修改或未使用批处理文件的文件 [英] Continuously check a file modified or not using batch file
本文介绍了连续检查已修改或未使用批处理文件的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建一个批处理文件,该文件将连续检查文件的修改日期是否更改.如果已更改,则显示消息框文件已被修改".我有一个简单的代码,但是在执行中显示了一些错误.
I am trying to create a batch file which is to continuously check the modified date of a file is changed or not. And if it is changed, then display a message box that "File has been modified". i have a simple code and but it showing some error in the execution..
@echo off
setlocal
set FileName=F:\test\tester.txt
set FileTime=0
:loop
for %%X in (%FileName%) do (
if %FileTime% NEQ %%~tX (
echo file modified
) else (
echo no change )
set FileTime=%%~tX
)
ping -n 10 localhost >nul 2>nul
goto :loop
pause
推荐答案
我的最终代码.感谢您的支持.
My final Code. Thanks for your supports.
@echo off
setlocal enableextensions disabledelayedexpansion
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do
set "dt=%%a"
set "td.YY=%dt:~2,2%"
set "td.YYYY=%dt:~0,4%"
set "td.MM=%dt:~4,2%"
set "td.DD=%dt:~6,2%"
set "filename=%td.MM%%td.DD%%td.YY%.txt
:loop
for %%i in (%filename%) do (
echo %%~ai|find "a" >nul && (
cscript MessageBox.vbs "Today's Schedule Changed. Modified Time: %time%. Please Check AVScheduler ON or OFF."
attrib -a %%i
) || (
rem echo no change
)
)
timeout 1 >nul
goto :loop
这篇关于连续检查已修改或未使用批处理文件的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文