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 20:16
中国DOS联盟论坛 » DOS学习入门 & 精彩文章 (教学室) » How should I modify this batch file? View 1,167 Replies 8
Original Poster Posted 2004-02-13 00:00 ·  中国 广东 河源 电信
高级用户
★★
Credits 916
Posts 201
Joined 2003-05-04 00:00
23-year member
UID 1849
Gender Male
Status Offline
Like this:
dready C: /w
if ERRORLEVEL 2 goto az
dready D: /w
if ERRORLEVEL 2 goto az
dready E: /w
if ERRORLEVEL 2 goto az
...
dready z: /w
if ERRORLEVEL 2 goto az

(What I mean is, if the return code is 2, then execute “az” and stop doing dready on the following partitions.)

I changed it to:
for %%1 in (d e f g h i j k l m n o p q r s t u v w) do dready %%1: /w
if ERRORLEVEL 2 goto az
but it actually doesn't work. How should I change it?
Floor 2 Posted 2004-02-14 00:00 ·  中国 辽宁 沈阳 联通
铂金会员
★★★★
痴迷DOS者
Credits 5,798
Posts 1,924
Joined 2003-06-20 00:00
23-year member
UID 5583
Gender Male
From 金獅電腦軟體工作室
Status Offline
The dready in your batch file is an external command, right? You can try the SHIFT command.

:TOP
dready %1: /w
if ERRORLEVEL 2 goto az
SHIFT
GO TOP

:az

REM The startup parameters for this batch file are: d e f g h i j k l m n o p q r s t u v w x y z

I didn't actually do any concrete testing, so if there's anything inappropriate, please point it out.
熟能生巧,巧能生精,一艺不精,终生无成,精亦求精,始有所成,臻于完美,永无止境!
金狮電腦軟體工作室愿竭诚为您服务!
QQ群:8393170(定期清理不发言者)
个人网站:http://www.520269.cn
电子邮件:doujiehui@vip.qq.com
微信公众号: doujiehui
Floor 3 Posted 2004-02-14 00:00 ·  中国 广东 河源 电信
高级用户
★★
Credits 916
Posts 201
Joined 2003-05-04 00:00
23-year member
UID 1849
Gender Male
Status Offline
If I want to apply it to a loop, how should I change it?
Floor 4 Posted 2004-02-14 00:00 ·  中国 辽宁 沈阳 联通
铂金会员
★★★★
痴迷DOS者
Credits 5,798
Posts 1,924
Joined 2003-06-20 00:00
23-year member
UID 5583
Gender Male
From 金獅電腦軟體工作室
Status Offline
The dready in your batch file is an external command, right? You can try the SHIFT command.
Modified version: (not tested, no idea whether it can work, just for discussion)

:TOP
CALL %0 c d e f g h i j k l m n o p q r s t u v w x y z
dready %1: /w
if ERRORLEVEL 2 goto az
SHIFT
GO TOP

:az

REM The startup parameters for this batch file are: c d e f g h i j k l m n o p q r s t u v w x y z

I didn't actually do any concrete testing, so if there's anything inappropriate, please point it out.
熟能生巧,巧能生精,一艺不精,终生无成,精亦求精,始有所成,臻于完美,永无止境!
金狮電腦軟體工作室愿竭诚为您服务!
QQ群:8393170(定期清理不发言者)
个人网站:http://www.520269.cn
电子邮件:doujiehui@vip.qq.com
微信公众号: doujiehui
Floor 5 Posted 2004-02-14 00:00 ·  中国 广东 河源 电信
高级用户
★★
Credits 916
Posts 201
Joined 2003-05-04 00:00
23-year member
UID 1849
Gender Male
Status Offline
Kinglion, your method doesn't work. What should I do?
Floor 6 Posted 2004-02-16 00:00 ·  中国 河北 石家庄 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re walu:

The following code is modified from Kinglion's code, you can try it. Also, you've asked many similar questions. Is there some specific need? Learning how to draw inferences from one example should be the most important thing.


@echo off
if not == goto top
call %0 c d e f g h i j k l m n o p q r s t u v w x y z
goto end

:top
dready %1: /w
if ERRORLEVEL 2 goto az
shift
goto top

:az
rem insert your own processing code

:end



※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 7 Posted 2004-02-16 00:00 ·  中国 广东 河源 电信
高级用户
★★
Credits 916
Posts 201
Joined 2003-05-04 00:00
23-year member
UID 1849
Gender Male
Status Offline
RE willsort:
I'm making some boot disks, so I've asked quite a few batch file questions, and each time I've received your enthusiastic help. Let me thank you all together here! I also want to learn by drawing inferences from one example, but I don't have any foundation at all, nor have I studied it systematically, only picked up some fragments. There are even some batch files whose meaning I can't understand at all, and I also can't find any books about batch files and DOS in bookstores. Do you have any batch file e-books? I once looked online for one called "Batch File Basics and Techniques", but unfortunately couldn't find it. Actually, you're already a top expert at batch files, so why not write a book or a detailed learning article, so we can learn from it?
For example: if == goto sub
if == goto end
What do these two lines mean?
Floor 8 Posted 2004-02-16 00:00 ·  中国 河北 石家庄 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re walu:

As for e-books, there used to be some scattered versions, and I myself once wrote some special-topic material, but since it was only for private study, I never organized it. Later, it was almost completely lost in one hard disk failure after another, so I can only regretfully say I can't satisfy your request.

And there really are very few advanced works on batch file study. Most of them are scattered through early computer magazines and foreign-language DOS textbooks. That's how I accumulated my experience.

The idea of publishing a book myself is too unrealistic for me. If the compilers of this site's DOS books are willing to devote more space to batch files, then I can do my best to provide support.
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 9 Posted 2004-02-16 00:00 ·  中国 河北 石家庄 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re walu:

if == goto sub
---------------
Taken literally, it means that if the first command-line parameter used to call this program is $sub, then jump directly to the SUB label.

In general, this is a commonly used technique when a batch program calls itself with various parameters. This lets it skip over some data-initialization modules that are needed when it runs without parameters. $sub is not any special keyword; it's just the notation I habitually use when calling a subroutine. Of course, it could also be some other parameter string that users normally would not use when running the program.

if == goto end
---------------
Taken literally, it means that if the environment variable predrive is empty, then jump directly to the end label.

In the specific case where it was used (that is, in the batch file I wrote), it means that when the sub subroutine in the program is called for the first time (that is, called with the parameter $sub d), predrive still has no value, so it needs to jump to end to assign a value to it (that is, d), so it can be used in the second round of calling (that is, called with the parameter $sub e).



※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Forum Jump: