中国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-08-13 04:13
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS学习入门 & 精彩文章 (教学室) » [Help] How can I make this batch file more concise?
Printable Version  1,352 / 4
Floor1 walu Posted 2004-01-14 00:00
高级用户 Posts 201 Credits 916
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
Floor2 iceboy Posted 2004-01-14 00:00
银牌会员 Posts 512 Credits 1,681
Floor3 GOTOmsdos Posted 2004-01-15 00:00
铂金会员 Posts 1,827 Credits 5,154
Correction follows
Floor4 iceboy Posted 2004-01-16 00:00
银牌会员 Posts 512 Credits 1,681
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?)
Floor5 GOTOmsdos Posted 2004-01-17 00:00
铂金会员 Posts 1,827 Credits 5,154
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)























































































































































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