Computing.Net > Forums > Disk Operating System > Setting batch file to run only 5 times

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Setting batch file to run only 5 times

Reply to Message Icon

Name: Nick
Date: December 6, 2001 at 14:42:35 Pacific
Comment:

Does anyone know how to do this, I was thinking along the lines setting a value of 1 initially in a separate count.txt file, then every time my prog.bat ran telling it to read count.txt and add 1 to the existing value. Then to continually check if the value goes over 5 and delete the prog.bat.

I have tried to do this myself but don't know the proper code, can anyone help - Thank's



Sponsored Link
Ads by Google

Response Number 1
Name: astroraptor
Date: December 6, 2001 at 17:12:34 Pacific
Reply:

I'm working on it...


0

Response Number 2
Name: Nick
Date: December 7, 2001 at 07:50:27 Pacific
Reply:

Ok, thank's I will await your reply


0

Response Number 3
Name: astroraptor
Date: December 7, 2001 at 13:08:26 Pacific
Reply:

Just send me an e-mail or give me your e-mail, it might take me a bit and by then the message will be on the 5th page if not more, hehe :)


0

Response Number 4
Name: Laurence
Date: December 8, 2001 at 02:29:29 Pacific
Reply:


Batfiles: The DOS batch file programming handbook & tutorial


This one will delete itself
after the 5th run. Doskey must
be in the path (or running).


:: delme5.bat
:: deletes self after the fifth time run
@echo off
ECHO %0 |FIND.EXE ":\" >nul
IF errorlevel=1 ECHO Enter complete path to %0
IF errorlevel=1 GOTO end
:: This example counts up to five and will echo a message to the
:: screen every fifth time it is run.
SET cnt=

:check
SET cnt=%cnt%*
MEM/C |FIND.EXE "DOSKEY" >nul
IF not errorlevel=1 GOTO start
IF "%cnt%"=="**" GOTO nodoskey
LH DOSKEY.COM
GOTO check

:start
SET cnt=
SET src=
IF exist %0.bat SET src=%0.bat
IF "%src%"=="" IF exist %0 SET src=%0
IF "%src%"=="" ECHO "%0" must exist as entered
IF "%src%"=="" GOTO end
:: * your code for every run goes here *

SET key=::#
ECHO %key%# Do not remove or change this line!>> %src%

:: Change the 5's below to set the counter.
FIND/C "%key%#" nul %Set counter here%
IF errorlevel=1 GOTO end

:clear
FIND/V "%key%#" %src%
:: ECHO %src% has run 5 times

:: *your code for run 5 goes here*

GOTO delete
GOTO end

:nodoskey
SET cnt=
ECHO. unable to load doskey.com
GOTO end

:delete
SET key=
ECHO. Deleting %src%
::doskey delme=del %src% $t exit $t set src=$t doskey delme=$t cls
::echo delme | command /k

:end
SET key=
SET src=


0

Response Number 5
Name: Laurence
Date: December 8, 2001 at 02:34:45 Pacific
Reply:

Try again. Watch for wrapped lines.
Note: You must uncomment the lines in the
delete module to do the actual deleting.

:: delme5.bat
:: deletes self after the fifth time run
@echo off
ECHO %0 |FIND.EXE ":\" >nul
IF errorlevel=1 ECHO Enter complete path to %0
IF errorlevel=1 GOTO end
:: This example counts up to five and will echo a message to the
:: screen every fifth time it is run.
SET cnt=

:check
SET cnt=%cnt%*
MEM/C |FIND.EXE "DOSKEY" >nul
IF not errorlevel=1 GOTO start
IF "%cnt%"=="**" GOTO nodoskey
LH DOSKEY.COM
GOTO check

:start
SET cnt=
SET src=
IF exist %0.bat SET src=%0.bat
IF "%src%"=="" IF exist %0 SET src=%0
IF "%src%"=="" ECHO "%0" must exist as entered
IF "%src%"=="" GOTO end
:: * your code for every run goes here *

SET key=::#
ECHO %key%# Do not remove or change this line!>> %src%

:: Change the 5's below to set the counter.
FIND/C "%key%#" nul %Set counter here%
IF errorlevel=1 GOTO end

:clear
FIND/V "%key%#" %src%
:: ECHO %src% has run 5 times

:: *your code for run 5 goes here*

GOTO delete
GOTO end

:nodoskey
SET cnt=
ECHO. unable to load doskey.com
GOTO end

:delete
SET key=
ECHO. Deleting %src%
::doskey delme=del %src% $t exit $t set src=$t doskey delme=$t cls
::echo delme | command /k

:end
SET key=
SET src=



0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Setting batch file to run only 5 times

Batch file to run on log off! www.computing.net/answers/dos/batch-file-to-run-on-log-off/14751.html

Dos batch file to exclude days!! www.computing.net/answers/dos/dos-batch-file-to-exclude-days/13643.html

FTP only when file in directory www.computing.net/answers/dos/ftp-only-when-file-in-directory/14366.html