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-01 14:44
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Can batch processing achieve sequence numbers? View 1,749 Replies 7
Original Poster Posted 2005-11-22 23:46 ·  中国 重庆 渝中区 电信
银牌会员
★★★
Credits 2,165
Posts 730
Joined 2004-04-21 00:00
22-year member
UID 22966
Gender Male
Status Offline
For example, to generate sequences like 1, 2, 3... 999, how to do it?

Requirements: Do not use commands under XP.
Floor 2 Posted 2005-11-23 07:57 ·  中国 广东 广州 白云区 电信
荣誉版主
★★★
Credits 718
Posts 313
Joined 2005-09-26 00:00
20-year member
UID 42844
Gender Male
Status Offline
"Requirement: cannot use commands under XP. " How to understand this? That is, only use DOS's COMMAND?

If that's the case, using WAIT and COUNTER should be possible. Idea: Refer to PLC programming to use "timer and counter relay" to achieve long delay mode, timing drive, counting step activation.

But BATCH FILE may have a simpler way. Please discuss everyone:>
Floor 3 Posted 2005-11-23 19:42 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
D◎$ Fαп
Credits 4,562
Posts 1,883
Joined 2004-01-19 00:00
22-year member
UID 15812
Gender Male
From 广东广州
Status Offline
It can be done with the third - party tool Strings.com.
----====≡≡≡≡ 我的至爱,永远是MSDOS!≡≡≡≡====----
Floor 4 Posted 2005-11-25 21:37 ·  中国 山西 运城 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re bush:

Recently, there seem to be many problems that need to be solved under MSDOS/Win9x_COMMAND, which is very similar to my situation three years ago, and I feel like meeting an old acquaintance from afar.

Regarding generating sequence numbers, I remember mentioning it in a past reply, but it's hard to find now; if I have time, I will organize it into my " An Unusual Batch Programming" topic, please wait.

Now provide a relatively similar code , which uses double loop nesting to generate and process sequence numbers with and without prefix 0 between 0-9 and 10-99.

Change the file name to 001.txt 010.txt...100.txt
http://www.cn-dos.net/forum/viewthread.php?tid=14512

[ Last edited by willsort on 2005-11-25 at 21:54 ]
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 5 Posted 2005-11-26 00:07 ·  中国 重庆 渝中区 电信
银牌会员
★★★
Credits 2,165
Posts 730
Joined 2004-04-21 00:00
22-year member
UID 22966
Gender Male
Status Offline
Thanks willsort, my problem has been solved!
Floor 6 Posted 2005-11-26 00:12 ·  中国 重庆 渝中区 电信
银牌会员
★★★
Credits 2,165
Posts 730
Joined 2004-04-21 00:00
22-year member
UID 22966
Gender Male
Status Offline
The cause is like this. Got a download package of a website, came back and saw it was incomplete. Had to check to know which files were missing, a thankless task! And these file names are composed of sequence numbers, like this: www.xxx.com/xxx/file1.html、www.xxx.com/xxx/file2.html……www.xxx.com/xxx/file389.html.
Fiddled around for a long time and came up with some batch processing solutions. The idea was to generate sequence numbers first and then use exist to judge.

Before starting, for safety, changed.html to.htm
a.bat
b 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

;Actually the first batch processing file was also generated with batch processing.
b.bat
@echo off
for %%a in (1,2,3,4,5,6,7,8,9) do call c node%%a.htm
:redo
if "%1" == "" goto end
for %%a in (0,1,2,3,4,5,6,7,8,9) do call c node%1%%a.htm
if errorlevel 2 goto end
shift
goto redo
:end

c.bat
@echo off
if not exist %1 echo %1 >> urls.lst
echo on

The finally obtained urls.lst is the needed file. Hehe, then batch process to download ~

[ Last edited by bush on 2005-11-26 at 00:13 ]
Floor 7 Posted 2005-11-26 11:42 ·  中国 辽宁 锦州 中移铁通
荣誉版主
★★★
Credits 1,338
Posts 356
Joined 2005-07-15 12:09
21-year member
UID 40733
Gender Male
Status Offline
It's simple under CMD, just one statement can do it.

for /l %i in (1,1,389) do @if not exist file%i.html echo.file%i.html>>urls.lst


For downloading things like this, I usually use curl or wget, and then batch organize, which is very convenient.
Floor 8 Posted 2005-11-26 17:21 ·  中国 山西 大同 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline

—————————————— willsort Moderation Record ——————————————
Merge Topic: {17950} Talk about an Example of Solving Problems with Batch Recently (Sequence) — Just Showing Off
Merge Reason: The two topics have direct contextual connections
—————————————— willsort Moderation Record ——————————————



:: Count.bat - Generate a serial of numbers
:: Will Sort - 2005-11-26 - WinXP_CMD/MSDOS7.10/MSDOS6.22
:: Description: An independently runnable example program that outputs a sequence of numbers from 1 to 123 to a file
:: It can be simply modified to generate sequence numbers of any number of digits, any interval, and any format
:: Even decimals are possible to generate.
:: Link: http://www.cn-dos.net/forum/viewthread.php?tid=17883
@echo off
if "%1"==":" goto %2
set _prog=%0
call %_prog% : loop1 0 1 2 3 4 5 6 7 8 9
set _prog=
set _start=
set _break=
goto end

:loop1
if "%3"=="" goto end
if "%3"=="0" call %_prog% : loop2 0 1 2 3 4 5 6 7 8 9
:: If prefix 0 is needed for the generated sequence numbers, omit the above line and also delete the next line's if not "%3"=="0"
if not "%3"=="0" call %_prog% : loop2 %30 %31 %32 %33 %34 %35 %36 %37 %38 %39
if "%_break%"=="true" goto end
shift
goto loop1

:loop2
if "%3"=="" goto end
if "%3"=="0" call %_prog% : loop3 0 1 2 3 4 5 6 7 8 9
:: If prefix 0 is needed for the generated sequence numbers, omit the above line and also delete the next line's if not "%3"=="0"
if not "%3"=="0" call %_prog% : loop3 %30 %31 %32 %33 %34 %35 %36 %37 %38 %39
if "%_break%"=="true" goto end
shift
goto loop2

:loop3
if "%3"=="" goto end
if "%3"=="1" set _start=true
if "%_start%"=="true" echo.%3>>sn.txt
:: The above line is the functional code for counting. The example only outputs numbers to a file
if "%3"=="123" set _break=true
if "%3"=="123" goto end
:: _start is the mark to start counting, 1 is the boundary to start counting
:: _break is the mark to interrupt counting, 123 is the boundary to interrupt counting
shift
goto loop3

:end


[ Last edited by willsort on 2005-11-26 at 18:16 ]
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Forum Jump: