Jump to content

Recommended Posts

Posted

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?


Posted

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

Posted
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.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

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