China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-03 01:02
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Problems with counting View 2,260 Replies 22
Original Poster Posted 2007-01-01 12:11 ·  中国 北京 中国科学院研究生院
银牌会员
★★★
Credits 1,187
Posts 555
Joined 2006-12-21 07:35
19-year member
UID 74129
Gender Male
Status Offline
How to write a batch script that automatically remembers the number of times it has run?
Floor 2 Posted 2007-01-01 12:32 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
Write the number of runs into a file or the registry
Floor 3 Posted 2007-01-01 12:46 ·  中国 北京 中国科学院研究生院
银牌会员
★★★
Credits 1,187
Posts 555
Joined 2006-12-21 07:35
19-year member
UID 74129
Gender Male
Status Offline
Can't it be implemented in P without rewriting the registry and without additional files?
Floor 4 Posted 2007-01-01 12:53 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
Of course it's also possible, but it's a bit more troublesome
Floor 5 Posted 2007-01-01 13:11 ·  中国 北京 中国科学院研究生院
银牌会员
★★★
Credits 1,187
Posts 555
Joined 2006-12-21 07:35
19-year member
UID 74129
Gender Male
Status Offline
Then please post the code. Thanks
Floor 6 Posted 2007-01-01 16:25 ·  中国 广西 南宁 联通
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
The last line of the batch processing must be an empty line

1、The simplest way is to add in the batch processing:
set/p=:<nul>>%~nx0

Calculate the number of ":"

2、Display the current running times:
@echo off
for /f "tokens=1,2* delims=:" %%i in ('findstr /nv "`" %~nx0') do set /a N=%%i-1
for /f "skip=%N% delims=" %%i in (%~nx0) do (
for %%n in (%%i) do set /a %%n+=1)
set /a :+=1
echo.&echo. The %:% run. &echo.
set/p=: <nul>>%~nx0
pause
exit


Floor 7 Posted 2007-01-02 01:07 ·  中国 北京 中国科学院研究生院
银牌会员
★★★
Credits 1,187
Posts 555
Joined 2006-12-21 07:35
19-year member
UID 74129
Gender Male
Status Offline

Many Thanks

Happy New Year
Floor 8 Posted 2007-01-02 01:09 ·  中国 北京 中国科学院研究生院
银牌会员
★★★
Credits 1,187
Posts 555
Joined 2006-12-21 07:35
19-year member
UID 74129
Gender Male
Status Offline
It has been debugged. It's very good. But I still need to study it. I haven't looked at the code carefully yet. Thanks first.
Floor 9 Posted 2007-01-07 02:28 ·  中国 北京 中国科学院研究生院
银牌会员
★★★
Credits 1,187
Posts 555
Joined 2006-12-21 07:35
19-year member
UID 74129
Gender Male
Status Offline
There is a problem with that code? Can only remember to 2, and then always 2, who will solve it?
Floor 10 Posted 2007-01-07 04:55 ·  中国 辽宁 联通
银牌会员
★★★
Credits 1,212
Posts 464
Joined 2006-12-13 21:11
19-year member
UID 73417
Gender Male
Status Offline
Is it possible to write one with VBS? Blame me for being ignorant, sweat~~

[ Last edited by jmz573515 on 2007-1-22 at 10:16 PM ]
Floor 11 Posted 2007-01-07 04:59 ·  中国 北京 中国科学院研究生院
银牌会员
★★★
Credits 1,187
Posts 555
Joined 2006-12-21 07:35
19-year member
UID 74129
Gender Male
Status Offline
waw...

Here comes another VBS one

Hehe......
Okay, thank you.
Floor 12 Posted 2007-01-07 05:00 ·  中国 北京 中国科学院研究生院
银牌会员
★★★
Credits 1,187
Posts 555
Joined 2006-12-21 07:35
19-year member
UID 74129
Gender Male
Status Offline
Can we can solve this problem only in BAT format? Thanks
Floor 13 Posted 2007-01-07 05:18 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Demonstration code:

@echo off
:: Only count when this script is not closed
:loop
cls
set /a num+=1
echo This is the %num%th run
pause
goto loop
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 14 Posted 2007-01-07 05:37 ·  中国 北京 中国科学院研究生院
银牌会员
★★★
Credits 1,187
Posts 555
Joined 2006-12-21 07:35
19-year member
UID 74129
Gender Male
Status Offline
What I want is not this situation. What I mean is that every time it runs, it counts once. How to achieve it? Only using bat
Floor 15 Posted 2007-01-07 05:43 ·  中国 广东 广州 天河区 电信
高级用户
★★★
潜水修练批处理
Credits 788
Posts 366
Joined 2006-12-31 02:43
19-year member
UID 75048
Gender Male
Status Offline
echo content >> batch file itself
Just use this
The principle is roughly like this, if you are interested, you can make some corrections and so on

[ Last edited by dikex on 2007-1-6 at 04:45 PM ]
Forum Jump: