Subj : Re: Timed Event in windows file? (batch possibly?) To : comp.programming From : Rob Morris Date : Tue Jul 19 2005 03:50 pm ratedr1@aol.com wrote: > Is it possible to add a timer/timed event in a batch or txt file? [Snip!] Hi, I think there are better ways to script on Windows than using batch files, but you can still do fairly powerful stuff with them, mainly with the 'FOR' and 'IF' commands. There is a %TIME% environment variable, which you could send to a file, and then parse it using the 'FOR /f' command (it reads through files and can be told a separator token). Maybe something like this: @echo off : start rem Put time in h:m:s into a file echo %time% >temp_time.txt rem Pull out number of seconds, loop until it's zero. for /f "delims=:. tokens=3" %%i in (temp_time.txt) do ( if %%i==00 ( echo 0 seconds. Starting... ) else ( echo %%i goto start ) ) Now, this is fairly naff and is linked to seconds in the minute, not time elapsed. But it could be extended to a whole list of commands by using another FOR loop with a list of commands and when to do them. e.g. a control.txt file with a list of what to do === control.txt === 00:echo 00:echo Hello 15:echo 15 30:echo 30 =================== A helper, wait_until.bat === wait_until.bat ========== @echo off : start rem Put time in h:m:s into a file echo %time% >temp_time.txt rem Pull out number of seconds, loop until it's zero. for /f "delims=:. tokens=3" %%i in (temp_time.txt) do ( if %%i neq %1 ( goto start ) ) =========================== And the main file: === timing.bat === @echo off rem Read control.txt one set of commands at a time rem for /f "delims=: tokens=1,2,3" %%a in (control.txt) do ( echo Current line says %%a %%b %%c wait_until %%a @echo off rem Now do commands %%b %%c ) ================== You see? timing.bat reads control.txt, waits until the number of seconds it's told to, then executes up to two commands (the second and third tokens on the line in control.txt). Then it reads the next line of control.txt, and so on. (Note the separate wait_until.bat, I had problems trying to do it all in one file). Anyway, this isn't a great way of doing things. I'm sure someone could write something better in C in about five minutes. I ploughed on with it once I'd started but I don't think it's very good. Good luck anyway. Cheers, Rob M -- Rob Morris: arr emm four four five (at) cam dot ac dot uk .