中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-23 16:40
47,812 topics / 349,917 posts / today 0 new / 48,274 members
DOS学习入门 & 精彩文章 (教学室) » How should I modify this batch file?
Printable Version  1,325 / 8
Floor1 walu Posted 2004-02-13 00:00
高级用户 Posts 201 Credits 916
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?
Floor2 Kinglion Posted 2004-02-14 00:00
铂金会员 Posts 1,924 Credits 5,798 From 金獅電腦軟體工作室
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.
Floor3 walu Posted 2004-02-14 00:00
高级用户 Posts 201 Credits 916
If I want to apply it to a loop, how should I change it?
Floor4 Kinglion Posted 2004-02-14 00:00
铂金会员 Posts 1,924 Credits 5,798 From 金獅電腦軟體工作室
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.
Floor5 walu Posted 2004-02-14 00:00
高级用户 Posts 201 Credits 916
Kinglion, your method doesn't work. What should I do?
Floor6 willsort Posted 2004-02-16 00:00
元老会员 Posts 1,512 Credits 4,432
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



Floor7 walu Posted 2004-02-16 00:00
高级用户 Posts 201 Credits 916
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?
Floor8 willsort Posted 2004-02-16 00:00
元老会员 Posts 1,512 Credits 4,432
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.
Floor9 willsort Posted 2004-02-16 00:00
元老会员 Posts 1,512 Credits 4,432
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).



[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023