Infolinks

How to create a batch file (.bat or .cmd) with an infinite running loop on Windows XP and Windows 7
by: Revengsky Joseph D. Reyes – a.k.a rjdreyes

Creating an infinite loop on a batch file is easy, this works both on Windows OS (XP/7):

Open a Notepad then copy and paste the example code below:

FOR WINDOWS 7:
@echo off
:begin
if exist “H:Temptextme.txt” (
@echo file exist
) else (
@echo file not exist
)
timeout 5
goto begin

(Note: @echo is a command to display messages whereas if @echo off will not to display echo settings. :begin is the start of the loop process, whereas the goto begin goes back to start process. if exist is an if condition level to check if the file exist, if not, then it goes to else condition. The timeout is a parameter to wait the specified time period (in seconds) until the key press is establish, otherwise, it will execute the next line when the timeout period is establish.)

FOR WINDOWS XP:
@echo off
:begin
if exist “H:Temptextme.txt” (
@echo file exist
) else (
@echo file not exist
)
sleep 5
goto begin

(Note: sleep is also same as timeout on Windows 7, if you don’t have this batch command, perhaps you need to install Windows Server 2003 Resource Kit Tools on your Windows XP OS. Otherwise, you can used an alternative command see below.)

ALTERNATIVE INFINITE LOOP BATCH COMMAND (WITH TIMEOUT WORKS BOTH ON WINDOWS XP AND WINDOWS 7):

@echo off
:begin
if exist “H:Temptextme.txt” (
@echo file exist
) else (
@echo file not exist
)
ping -n 5 127.0.0.1 > nul
goto begin

(Note: ping is a command to send echo request, whereas the -n (count) how many times it will send echo request on the given address/host, the 127.0.0.1 is your computer/localhost address, then > nul is a device defined by OS in which, it just simply redirect and throw away)

SIMPLE LOOP IMPLEMENTATION:

:begin
->PARAMETERS, ARGUMENTS, CONDITION,COMMAND (WILL REPEAT IN HERE)
goto begin

Save the file as .bat or .cmd – myloopbatchfile.bat (as an example), Double-click the file to run it or put it on the Startup Menu Program to launch the batch file instantly when the computer boots on the Windows OS.

Try to explore its usages, then comment here if you found one interesting to share.
That’s all! I hope this guide and tips helps you out! Cheers! 😀

(Note: Microsoft (Windows XP and 7 OS), CMD, Command Prompt, Batch Command – Logo/Images/Pictures has a respective copyright. I used it for demonstration purpose only.)

Related Entries / Links / Sources / Articles / Sources:
Microsoft – Download Windows Server 2003 Resource Kit Tools – Official Site

Related Posts Plugin for WordPress, Blogger...
Share

Leave a Reply

Your email address will not be published. Required fields are marked *

Infolinks