Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.


UPDATE!!!


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

share|improve this question

2 Answers 2

I would suggest not re-inventing the wheel and use an application that is well defined and designed for such a purpose.

Tail for Windows

share|improve this answer
    
That's exactly what I don't want, I need this because my purpose ain't to use another program I need this to work in batch. –  Linus Apr 23 '13 at 8:44
    
You are already using utilities. What do you think ping is? –  dmcgill50 Apr 24 '13 at 17:46

Tail for Windows looks nice, but following @dmcgill50 recommendation I just try it and not work for me (tried with a file in Dropbox, Win8 x64). Would be nice to know one way to do this.

Maybe one of the recomendations in this page can help you:

10 Tools to Monitor Files and Folders for Changes in Real Time

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.