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-13 05:21
中国DOS联盟论坛 » DOS学习入门 & 精彩文章 (教学室) » [Help] How can I make this batch file more concise? View 1,354 Replies 4
Original Poster Posted 2004-01-14 00:00 ·  中国 广东 河源 电信
高级用户
★★
Credits 916
Posts 201
Joined 2003-05-04 00:00
23-year member
UID 1849
Gender Male
Status Offline
The contents are as follows:

IF NOT EXIST d:\win.gho GOTO e
Ghost.exe -CLONE,MODE=PDUMP,SRC=1:1,DST=d:\WIN.gho -Z9 -sure -fx
call bfyz.bat

:e
IF NOT EXIST e:\win.gho GOTO f
Ghost.exe -CLONE,MODE=PDUMP,SRC=1:1,DST=E:\WIN.gho -Z9 -sure -fx
call bfyz.bat

:f
IF NOT EXIST f:\win.gho GOTO g
Ghost.exe -CLONE,MODE=PDUMP,SRC=1:1,DST=f:\WIN.gho -Z9 -sure -fx
call bfyz.bat

......

:y
IF NOT EXIST y:\win.gho GOTO z
Ghost.exe -CLONE,MODE=PDUMP,SRC=1:1,DST=y:\WIN.gho -Z9 -sure -fx
call bfyz.bat

:z
end
Floor 2 Posted 2004-01-14 00:00 ·  中国 湖北 武汉 联通
银牌会员
★★★
Credits 1,681
Posts 512
Joined 2003-08-02 00:00
23-year member
UID 7953
Gender Male
Status Offline
Somehow somewhere I've got to choose.
No matter if it is win or lose.
Floor 3 Posted 2004-01-15 00:00 ·  中国 广东 广州 电信
铂金会员
★★★★
C++启程者
Credits 5,154
Posts 1,827
Joined 2003-07-18 00:00
23-year member
UID 7105
Gender Male
Status Offline
Correction follows
Floor 4 Posted 2004-01-16 00:00 ·  中国 湖北 武汉 联通
银牌会员
★★★
Credits 1,681
Posts 512
Joined 2003-08-02 00:00
23-year member
UID 7953
Gender Male
Status Offline
No, that batch file searches for this win.gho from drive Z to drive C, (if both D and E have it, then it uses the one on drive D)
Look carefully, it's not like what you said...

I can't understand your second batch file... (can it really be done?)
Somehow somewhere I've got to choose.
No matter if it is win or lose.
Floor 5 Posted 2004-01-17 00:00 ·  中国 广东 广州 电信
铂金会员
★★★★
C++启程者
Credits 5,154
Posts 1,827
Joined 2003-07-18 00:00
23-year member
UID 7105
Gender Male
Status Offline
IF NOT EXIST d:\win.gho GOTO e
Ghost.exe -CLONE,MODE=PDUMP,SRC=1:1,DST=d:\WIN.gho -Z9 -sure -fx
call bfyz.bat
:e
...........

Oh, that's right, this batch file means execute them all, but I think that most likely wasn't the OP's original intention. Because this batch file itself is repetitive, it loses the actual effect of the "if not exist ...." assumption. (Because no matter what, it is still going to execute: E:F:G ,,,,,:Z)
I guess what the OP had in mind was that a backup had originally been made on one drive, but later he forgot which drive it was on, and now he wants to update that backup once; after finding and processing it, it should stop searching. To match that meaning, you should add goto end after each section, then add :end at the end, and only then would it match the OP's original intent.
But it still needs simplifying.

If the OP's original intention is to find one and process one, then this is enough:

Suitable for 2000 XP 2003:
for %%1 in (d e f ....z) do Ghost.exe -CLONE,MODE=PDUMP,SRC=1:1,DST=%%1:\WIN.gho -Z9 -sure -fx && bfyz.bat

Suitable for 98:
(unfortunately, right now these two tasks, ghost...... and bfyz.bat, can only be separated. In 98 I haven't found a way to put these two tasks together; if anyone can solve it that would be great. The moderator's batch file seems to execute only once and then end, because the FOR command only loops within the current statement; if it meets the GOTO condition, it jumps away, and then it doesn't even continue looping within the current statement)

for %%1 in (d e f ....z) do Ghost.exe -CLONE,MODE=PDUMP,SRC=1:1,DST=%%1:\WIN.gho -Z9 -sure -fx
for %%1 in (d e f ....z) do if exist %%1:\win.gho bfyz.bat

If the OP's original intention is to find the first one, process it, and then stop, then like this:

for %%1 in (z y x ....... d) do if exist %%1:\win.gho set vol=%%1
Ghost.exe -CLONE,MODE=PDUMP,SRC=1:1,DST=%vol%:\WIN.gho -Z9 -sure -fx
bfyz.bat

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
& &
& If you're interested, you can play around with the DIY fun of manually entering arguments! &
& &
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

You can make a simple batch file to experiment with it. First create a file in the root directories of your last two drives, with the contents “dddddddddddddddddddddd” and “eeeeeeeeeeeeeeeeeeeeee” respectively, both named "target.txt".
======================
Create a batch file named “oneput.bat” as follows:
(manual input all at once)
@echo off
:loop
shift
if %1#==# goto end
if not exist %1:\target.txt goto loop
dir %1:\target.txt
type %1:\target.txt
:end

When operating it, type
oneput d d e f g h i j k l m n o p q r s t u v w x y z and press Enter. (You need to enter one extra arbitrary character, because shift invalidates the first one; it's equivalent to there having already been one %1 before it)

=========================
Then create another batch file named “everyput.bat”: it looks a bit scary! If anyone can find a simpler way, please post it! Looking forward to it! ...I'm seriously depressed over this right now!

(interactive manual input) Actually this is hypothetical, because generally there aren't that many drives, so you only need to write it according to however many drives you have.

@echo off
:loop
if exist %vol%:\target.txt goto end
choice /c:defghijklmnopqrstuvwxyz /t:d,99 enter a drive letter

set vol=z
if errorlevel 23 goto loop
set vol=y
if errorlevel 22 goto loop
set vol=x
if errorlevel 21 goto loop
set vol=w
if errorlevel 20 goto loop
set vol=v
if errorlevel 19 goto loop
set vol=u
if errorlevel 18 goto loop
set vol=t
if errorlevel 17 goto loop
set vol=s
if errorlevel 16 goto loop
set vol=r
if errorlevel 15 goto loop
set vol=q
if errorlevel 14 goto loop
set vol=p
if errorlevel 13 goto loop
set vol=o
if errorlevel 12 goto loop
set vol=n
if errorlevel 11 goto loop
set vol=m
if errorlevel 10 goto loop
set vol=l
if errorlevel 9 goto loop
set vol=k
if errorlevel 8 goto loop
set vol=j
if errorlevel 7 goto loop
set vol=i
if errorlevel 6 goto loop
set vol=h
if errorlevel 5 goto loop
set vol=g
if errorlevel 4 goto loop
set vol=f
if errorlevel 3 goto loop
set vol=e
if errorlevel 2 goto loop
set vol=d
if errorlevel 1 goto loop

:end
dir %vol%:\target.txt
type %vol%:\target.txt
echo It''s done!

When operating it, type:
everyput d and press Enter (enter one each time: d......................z, until “It''s done! ” appears)























































































































































Forum Jump: