MSFN Forum: Premature ending of the FOR command - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Premature ending of the FOR command Is this possible? Rate Topic: -----

#1 User is offline   wonsleinad 

  • Newbie
  • Group: Members
  • Posts: 39
  • Joined: 09-May 04

Posted 19 May 2005 - 11:02 PM

I am working on making a stardard dos bootup disk. In the autoexec file I am using this command to get the cd drive lettter:

FOR %%i IN (C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF EXIST %%i:\whatever.txt SET CDROM=%%i:


The problem I'm having is I have more than one CDROM drive, and when it gets to the second drive (with no disk present) it automatically says something like:

Error Accessing E:\
Abort, Retry, or Fail?

Which messes up the automation of the autoexec. Is there a way that I can make the FOR command end as soon as it finds the first cdrom drive? I tried this but it did not work:

FOR %%i IN (C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF EXIST %%i:\whatever.txt SET CDROM=%%i: && goto next


OR, would there be a way were it goes ahead and scans through all the drives, but continues regardless of an error?


#2 User is offline   Martin Zugec 

  • MSFN Expert
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 1,373
  • Joined: 24-January 04

Posted 20 May 2005 - 12:00 AM

Your syntax will work - just add to the next row
:next


E.g.
FOR %%i IN (C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF EXIST %%i:\whatever.txt SET CDROM=%%i: && goto SkipDetection
:SkipDetection


#3 User is offline   wonsleinad 

  • Newbie
  • Group: Members
  • Posts: 39
  • Joined: 09-May 04

Posted 20 May 2005 - 08:59 AM

soulin, on May 20 2005, 01:00 AM, said:

Your syntax will work - just add to the next row
:next


No, it doesn't, I tried that. It still continues to go through the rest of the alphabet even after matching the file. Then, after going through the alphabet it doesn't even set the variable, it tries to set the variable as "D: && goto next". It's weird, it will work in the XP version of the command prompt, but when I try it with the MS-DOS 7 boot disk, it doesn't.

EDIT: I did accomplish the task with this command:

SET CDROM=C
IF EXIST %CDROM%:\whatever.txt GOTO done
SET CDROM=D
IF EXIST %CDROM%:\whatever.txt GOTO done
SET CDROM=E
IF EXIST %CDROM%:\whatever.txt GOTO done
SET CDROM=F
IF EXIST %CDROM%:\whatever.txt GOTO done
SET CDROM=G
IF EXIST %CDROM%:\whatever.txt GOTO done
SET CDROM=H
IF EXIST %CDROM%:\whatever.txt GOTO done
SET CDROM=I
IF EXIST %CDROM%:\whatever.txt GOTO done
SET CDROM=J
IF EXIST %CDROM%:\whatever.txt GOTO done
SET CDROM=K
IF EXIST %CDROM%:\whatever.txt GOTO done
SET CDROM=L
IF EXIST %CDROM%:\whatever.txt GOTO done
SET CDROM=M
IF EXIST %CDROM%:\whatever.txt GOTO done
SET CDROM=N
IF EXIST %CDROM%:\whatever.txt GOTO done
SET CDROM=O
IF EXIST %CDROM%:\whatever.txt GOTO done
SET CDROM=P
IF EXIST %CDROM%:\whatever.txt GOTO done
SET CDROM=Q
IF EXIST %CDROM%:\whatever.txt GOTO done
SET CDROM=R
IF EXIST %CDROM%:\whatever.txt GOTO done
SET CDROM=S
IF EXIST %CDROM%:\whatever.txt GOTO done
SET CDROM=T
IF EXIST %CDROM%:\whatever.txt GOTO done
SET CDROM=U
IF EXIST %CDROM%:\whatever.txt GOTO done
SET CDROM=V
IF EXIST %CDROM%:\whatever.txt GOTO done
SET CDROM=W
IF EXIST %CDROM%:\whatever.txt GOTO done
SET CDROM=X
IF EXIST %CDROM%:\whatever.txt GOTO done
SET CDROM=Y
IF EXIST %CDROM%:\whatever.txt GOTO done
SET CDROM=Z
IF EXIST %CDROM%:\whatever.txt GOTO done


Still I would like to use the for command if at all possible.

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy