Jump to content

Premature ending of the FOR command


Recommended Posts

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?

Link to comment
Share on other sites


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.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...