![]() |
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 13:55 |
47,812 topics / 349,917 posts / today 0 new / 48,273 members |
| DOS批处理 & 脚本技术(批处理室) » A Dilemma with a Simple Batch Processing |
| Printable Version 1,996 / 8 |
| Floor1 walu | Posted 2004-05-30 00:00 |
| 高级用户 Posts 201 Credits 916 | |
|
A Simple Batch Processing Dilemma
@ECHO OFF for %%i in (c d e f g h i j ) do if exist %%i:\SYS.gho GOTO label goto err :label label %%i:SYSTEM md %%i:\boot copy aa.txt %%i:\boot goto exit :err echo nofile :exit The meaning of the batch processing is: If the C partition has the SYS.GHO file, jump to :label to execute the corresponding commands and no longer continue to search other partitions, and so on... But when executed according to the above writing, an error occurs. Many netizens have given different solutions, but none are correct. Please ask experts like willsort to come to the rescue! |
|
| Floor2 haonanren | Posted 2004-05-30 00:00 |
| 初级用户 Posts 14 Credits 162 | |
|
It seems there is no problem.
|
|
| Floor3 haonanren | Posted 2004-05-30 00:00 |
| 初级用户 Posts 14 Credits 162 | |
| Floor4 Tamm | Posted 2004-05-30 00:00 |
| 中级用户 Posts 64 Credits 397 | |
|
Your batch processing, the error might be because %%i becomes invalid after leaving the FOR statement.
You can try seeing if this works: (not tested, I'm just providing an idea) @ECHO OFF SET SYS= for %%i in (c d e f g h i j ) do if exist %%i:\SYS.gho SET SYS=%%i if %SYS%*==* goto err GOTO :label :label label %SYS%: SYSTEM md %SYS%:\boot copy aa.txt %SYS%:\boot goto exit :err echo nofile :exit |
|
| Floor5 zhri | Posted 2004-05-30 00:00 |
| 高级用户 Posts 153 Credits 665 | |
|
如果存在c:\SYS.GHO
。。。。。。 If exist c:\SYS.GHO 。。。。。。 |
|
| Floor6 quya | Posted 2004-05-30 00:00 |
| 高级用户 Posts 172 Credits 558 From 江苏 | |
|
Just change it to the following. The main mistake in the program is that the %%i variable cannot be passed to the :label subroutine, so a global environment variable %mydrive% is used to transition.
@ECHO OFF for %%i in (c d e f g h i j ) do if exist %%i:\SYS.gho set mydrive=%%i if not defined mydrive (goto err) else (goto label) :label label %mydrive%:SYSTEM md %mydrive%:\boot copy aa.txt %mydrive%:\boot goto exit :err echo nofile :exit |
|
| Floor7 walu | Posted 2004-05-30 00:00 |
| 高级用户 Posts 201 Credits 916 | |
|
Thanks, Brother quya!
When running under WIN 98, if there are only partitions C and D, it displays "NOT READ READING DRIVE E". Under WIN XP, it is effective, but if there is a BOOT.INI file in the subsequent partition, even if there is a BOOT.INI file in partition C, it detects the subsequent partition instead of ending when it detects that there is one in partition C. I really hope that some brother can solve this long-unresolved problem, that is, it can run under both WIN XP and WIN 98. |
|
| Floor8 Tamm | Posted 2004-05-30 00:00 |
| 中级用户 Posts 64 Credits 397 | |
|
Here's the translation:
Another recommended complex but easy-to-operate and understand method: ======================== In the main batch processing: ======================== @ECHO OFF CALL TestDrv.bat C D E F G H I J K L M N O P Q R S T U V W X Y Z IF %SysDrv%*==* GOTO err GOTO label :label label %SysDrv%: SYSTEM md %SysDrv%:\boot copy aa.txt %SysDrv%:\boot goto exit :err echo nofile :exit =========================== The content of the sub-batch processing TestDrv.bat is as follows: =========================== @ECHO OFF SET SysDrv= :LOOP DReady %1 IF NOT ERRORLEVEL 1 IF EXIST %1:\BOOT.INI GOTO FOUND SHIFT IF %1*==* GOTO END GOTO LOOP :FOUND SET SysDrv=%1 :END ======================== In the sub-batch processing, a DReady.com is used, which is a small tool in Horst's Batch Tools. It is used to test the drive status and returns ERRORLEVEL to indicate whether the drive is ready. |
|
| Floor9 willsort | Posted 2004-06-02 00:00 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
Re All:
Brother walu's perseverance in this series of issues is quite admirable to me. Now, I am reposting the reply I made in the email here as a supplement. Since I didn't see this post before replying, there may be some repetitions with the views of various experts. Please don't mind!
|
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |