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-07-08 19:09
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Please provide the batch code that needs to be simplified so that I can help you with the simplification. View 2,210 Replies 5
Original Poster Posted 2006-01-10 11:29 ·  中国 河北 唐山 联通
版主
★★★
操作系统爱好者
Credits 1,113
Posts 392
Joined 2002-11-11 00:00
23-year member
UID 228
Gender Male
Status Offline
@echo off
for %%d in (c d e f g h i j k l m n o p q r s t u v w) do (
if exist %%d:\boot.ini (
set drv=%%d:
copy %%d:\boot.ini %%d:\boot.bak
goto end
)
)
:end
DOS之家 http://doshome.com 站长 葛明阳
Floor 2 Posted 2006-01-10 15:10 ·  中国 山西 大同 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re gmy:

The key improvement of your program is not in simplifying the statements, but in fault tolerance processing, because when going from C: to W:, it is very likely to encounter optical drives with no discs placed, network drives not connected to the network, and some special USB storage devices, etc. Using if exist to detect the existence of boot.iini here will encounter many unexpected problems.

The appearance of the third-party command dready has solved many problems. There have been many programs using it to loop through detecting drive sequences in this forum. You can search more for past posts . But it cannot solve all problems. For specific discussions, see .

Drive Polling Traversal Program Index
9637-12-walu-Drive Polling Traversal-1
http://www.cn-dos.net/forum/viewthread.php?tid=9637

11963-9-walu-Drive Polling Traversal-2
http://www.cn-dos.net/forum/viewthread.php?tid=11963

14620-9-ramjet-Drive Polling Traversal-3
http://www.cn-dos.net/forum/viewthread.php?tid=14620

14667-9-lin8197-Drive Polling Traversal-4
http://www.cn-dos.net/forum/viewthread.php?tid=14667

15599-9-GOTOmsdos-Drive Polling Traversal-5 (Link Bat)
http://www.cn-dos.net/forum/viewthread.php?tid=15599

Some Technical Discussions on HDKP
http://www.cn-dos.net/forum/viewthread.php?tid=12892#pid95281
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 3 Posted 2006-01-11 00:06 ·  中国 重庆 渝中区 电信
银牌会员
★★★
Credits 2,165
Posts 730
Joined 2004-04-21 00:00
22-year member
UID 22966
Gender Male
Status Offline
Wil is really a person with a heart!
Floor 4 Posted 2006-01-11 12:30 ·  中国 河北 石家庄 桥西区 联通
版主
★★★
操作系统爱好者
Credits 1,113
Posts 392
Joined 2002-11-11 00:00
23-year member
UID 228
Gender Male
Status Offline
re: willsort

Thank you. It has been solved.

@echo off
set drv=1
for %%i in (c d e f g h i j k l m n o p q r s t u v w) do if exist %%i:\boot.ini set drv=%%i
if %drv%==1 goto err

k
cls
echo OK! %drv%\boot.ini is found!
goto end

:err
cls
echo Sorry! boot.ini is not found!
goto end

:end
echo
echo
pause


[ Last edited by gmy on 2006-1-11 at 13:40 ]
DOS之家 http://doshome.com 站长 葛明阳
Floor 5 Posted 2006-01-11 14:43 ·  中国 山西 运城 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re gmy:

From the way your current program operates, it will always detect all drives from C to W, rather than immediately exiting as soon as a matching drive letter is detected, to avoid issues with unallocated drive letters and possible access to other drives. This is my modified version. Of course, it still can't fundamentally solve the drive letter access problem, just reduces the probability of problems occurring.


@echo off
if "%1"=="" goto ok
cls
for %%i in (c d e f g h i j k l m n o p q r s t u v w) do if exist %%i:\boot.ini %0 %%i

:err
echo Sorry! boot.ini is not found!
goto end

k
echo OK! %1\boot.ini is found !
goto end

:end
echo
echo
pause
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 6 Posted 2006-01-15 00:56 ·  中国 山西 运城 移动
中级用户
★★
Credits 241
Posts 131
Joined 2005-09-28 19:01
20-year member
UID 42920
Gender Male
Status Offline
Good post! The boot disk of the original poster I'm using right now, willsort's research on batch processing is really admirable!
房东说:这娃是个好孩子!
Forum Jump: