The other day I tried to make a batch file that will tell the user the Contest of a file when a specific text file updates/changes here's my code so far it doesn't work for some reason :S
@echo off SetLocal EnableDelayedExpansion :Try ping 127.0.0.1 -n 2 -w 1000 > NUL ping 127.0.0.1 -n %1 -w 1000 > NUL cls set test= for /F "delims=" %%a in (test.txt) do set test=!test! %%a if !test!==%VAR% ( goto Try ) else ( echo !test! set VAR1=!test! goto Try )
This is what I'm trying to do..
Wait 2 seconds. clear the screen. turn the content of test.txt to a variable. compare the variable with the other variable called %VAR%. since there's no variable to compare with in the beginning it goes to else statement and will output the content once. Then it will make the current content to a variable. It will go back to the beginning and try again.. If the test.txt have changed it will go to else once again. If not it will go back to try and wait for the file to change.
Please help me out it's very annoying.
So today I was messing around with the code and started to try other methods because I doubt this method would work.. So I thought "Out Side Of The Box". In my case I have a batch file that changes this text document called test.txt every now and then.. So I changed that one. This is the label
:Start cls set /p inp= echo %date% %inp% > test.txt echo 0 >> tmp.yml" goto Start
And I rewrote the other batch too..
@echo off color 04 :Try set /p texte=< test.txt if exist "tmp.yml" goto Changed goto Try :Changed del "tmp.yml" echo %texte% goto Try
Hope someone found this useful :D