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-02 02:24
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Help: Start a batch of batch files in a folder at intervals View 2,089 Replies 10
Original Poster Posted 2006-09-20 10:49 ·  中国 上海 浦东新区 电信
高级用户
★★
Credits 599
Posts 148
Joined 2003-10-30 00:00
22-year member
UID 12192
Gender Male
Status Offline
I need to start batch programs in about 100 folders. The folder names are different, but the batch file names are the same. It's about starting one batch every 4 or 5 seconds. The folder names follow a rule like abc1, abc2, abc3... Please, great guys, give me some advice on how to write the batch program. Thanks a lot!
Floor 2 Posted 2006-09-20 11:03 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
20-year member
UID 58987
From 湖南.娄底
Status Offline
I wonder if it meets the LZ's requirements.
@echo off
for /l %%i in (1,1,100) do (
if exist ".\abc%%i\name.bat" (
ping 127.1 -n 5 >nul 2>nul
call ".\abc%%i\name.bat"
)
)

[ Last edited by pengfei on 2006-9-20 at 11:06 ]
业精于勤而荒于嬉,形成于思而毁于随。
Floor 3 Posted 2006-09-20 11:13 ·  中国 上海 浦东新区 电信
高级用户
★★
Credits 599
Posts 148
Joined 2003-10-30 00:00
22-year member
UID 12192
Gender Male
Status Offline
What if the folders are changed to abc01, abc02, abc03......abc10, abc11, abc12..........?
Floor 4 Posted 2006-09-20 11:17 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
20-year member
UID 58987
From 湖南.娄底
Status Offline
Originally posted by qinqong at 2006-9-20 11:13:
What if the folders are changed to abc01, abc02, abc03......abc10, abc11, abc12..........?


It's okay, but it's relatively troublesome.
业精于勤而荒于嬉,形成于思而毁于随。
Floor 5 Posted 2006-09-20 11:23 ·  中国 广东 佛山 广东睿江科技有限公司
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
On the basis of the code of pengfei in , a little modification is made to get the following code. You can give it a try. If you also need to start the batch processing in the abc100 folder, you can modify the code by yourself:

@echo off
setlocal enabledelayedexpansion
for /l %%i in (1,1,99) do (
set num=0%%i
set num=!num:~-2!
if exist ".\abc!num!\name.bat" (
ping 127.1 -n 5 >nul 2>nul
call ".\abc!num!\name.bat"
)
)


[ Last edited by namejm on 2006-9-20 at 11:25 ]
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 6 Posted 2006-09-20 11:25 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
20-year member
UID 58987
From 湖南.娄底
Status Offline
Hehe~ Brother namejm has already fixed it!

@echo off
setlocal enabledelayedexpansion
for /l %%i in (1,1,108) do (
set files=%%i
if %%i LSS 10 set files=0%%i
if exist ".\abc!files!\name.bat" (
ping 127.1 -n 5 >nul 2>nul
call ".\abc!files!\name.bat"
)
)

[ Last edited by pengfei on 2006-9-21 at 02:31 ]
业精于勤而荒于嬉,形成于思而毁于随。
Floor 7 Posted 2006-09-20 11:29 ·  中国 上海 浦东新区 电信
高级用户
★★
Credits 599
Posts 148
Joined 2003-10-30 00:00
22-year member
UID 12192
Gender Male
Status Offline
Thanks, I haven't used batch processing for a long time, and I've forgotten many things. It seems I still need to often come here to recharge.

What does setlocal enabledelayedexpansion mean?

[ Last edited by qinqong on 2006-9-20 at 11:33 ]
Floor 8 Posted 2006-09-20 11:35 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
20-year member
UID 58987
From 湖南.娄底
Status Offline
setlocal enabledelayedexpansion is to enable delayed environment variables ~

[ Last edited by pengfei on 2006-9-20 at 11:38 ]
业精于勤而荒于嬉,形成于思而毁于随。
Floor 9 Posted 2006-09-22 01:10 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
```@echo off
for /f "delims=" %%i in ('dir /s /a /b your.bat') do call "%%i" & ping 4 -w 4000 -n 1 2>nul 1>nul
Execution time can be changed by modifying the parameter after -w, where 4000 represents 4 seconds```
Floor 10 Posted 2006-09-22 07:41 ·  中国 甘肃 张掖 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Moderator 3742668, using your.bat isn't very good, right!
Floor 11 Posted 2006-09-22 08:27 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
Building 10:

Moderator 3742668, using your.bat is not very good!

Please elaborate.
Forum Jump: