Batch file question (Yes, I know it's off-subject) 
Author Message
 Batch file question (Yes, I know it's off-subject)

While I was in Florida for Thanksgiving vacation (and got to walk the
hurricane damaged Pensacola Beach), I installed a CDRom in my sister's
computer. My nephew gets upset because sometimes, when the computer boots
up, it does not recognize the CDRom drive. I gave them a autoexec batch
file revision that checks to see if there are any files in drive D: before
it starts windows, and if it does not find any, it instructs the user to
reboot the system (the second boot always works, they say). Here's
approximately what I sent them

AUTOEXEC.bat
     (main commands deleted)
     IF EXIST D:*.* GOTO CONTINUE
     ECHO (instructions about rebooting)
     GOTO DONE
     :CONTINUE
     WIN
     :DONE

I'm not down there, so I can't test errorlevel's but what I'd like to do
is modify this code so that it checks the correct ERRORLEVELs for "Invalid
disk drive" versus "file not found" so that the batch file will work even
if a disk is not inserted in the drive. So, if someone has these numbers,
feed them to me. Then I can write a file more like this:

AUTOEXEC.bat
     (main commands deleted)
     DIR D:*.* > nul:
     IF ERRORLEVEL n GOTO suchandsuch
     IF ERRORLEVEL n-1 GOTO second
     Code for every errorlevel < n
     :suchandsuch
     Code for every every errorlevel >= n
     :second
     Code for errorlevel n

If someone can feed me the error numbers, I'll be glad to repost the
entire batch file if requested. If I lived closer to them, I'd go down and
do this myself, and I don't know when I'll have my CDRom working again (my
old 2X stopped working, so I'm buying a new one rather than fix the old).

John    



Thu, 21 May 1998 03:00:00 GMT  
 Batch file question (Yes, I know it's off-subject)

Quote:
> ..... a autoexec batch file revision that checks to see if there are any
> files in drive D: before>it starts windows, and if it does not find any, it
> instructs the user to>reboot the system .....

> ..... what I'd like to do is modify this code so that it checks the correct
> ERRORLEVELs for "Invalid disk drive" versus "file not found" so that the
> batch file will work even if a disk is not inserted in the drive.

John, I think you've set yourself an impossible task.  I'm not aware of any
way to determine in a batch file if a drive is either valid or ready.  If a
valid drive is not ready, DIR d:\*.* gets "Drive not ready" with ARF (Abort,
Retry, Fail) and returns ERRORLEVEL 0 for either Abort or Fail.  And a DIR to
an invalid drive get just an invalid drive message, which is also ERRORLEVEL 0.

Please let me know if you find a solution!  I spend an inordinate amount of
my time coding batch files and would be happy to add this to my list of things
that can be done.

For whatever it's worth, I've attached a simple batch file that'll check and
display the ERRORLEVEL.  I use it a lot for the same kind of thing you're
trying to do -- finding out the ERRORLEVEL that corresponds to a particular
error message.  Just CALL it immediately after the program or command you're
trying to figure out.  And be sure ECHO is OFF when that program or command is
issued.

Good luck!

UUENCODED by Trumpet for Windows [Version 1.0 Rev B final beta #4]

BEGIN--cut here--cut here----
begin 640 ERRORLVL.BAT
<uuencoded_portion_removed>

`
end
END--cut here--cut here----



Fri, 22 May 1998 03:00:00 GMT  
 Batch file question (Yes, I know it's off-subject)

Quote:

>> ..... a autoexec batch file revision that checks to see if there are any
>> files in drive D: before>it starts windows, and if it does not find any, it
>> instructs the user to>reboot the system .....

>> ..... what I'd like to do is modify this code so that it checks the correct
>> ERRORLEVELs for "Invalid disk drive" versus "file not found" so that the
>> batch file will work even if a disk is not inserted in the drive.

> John, I think you've set yourself an impossible task.  I'm not aware of any
> way to determine in a batch file if a drive is either valid or ready.  If a

        What about do something like this


                d:
                cd \
                dir > test.asc
                find "D:" test.asc > tout1.asc
        [if tout1 id sized > 0 you are in D:]
                find "1 File" test.asc > tout2.asc
        [similar than 1, dir of empty root is . <DIR> = 1 File]

                        ...
        [here you need a PD utility to del files sized 0. Could
be tons of versions on that]
                        ...

                if exist tout1.asc goto exitnodrive
                if exist tout2.asc goto exitnofiles
                goto exitgood
                :exitnodrive
                        ...    
                :exitnofiles
                        ...
                :exitgood
                del t*.asc
                c:
                cd \

        Cheers



Sat, 23 May 1998 03:00:00 GMT  
 Batch file question (Yes, I know it's off-subject)

 > ..... a autoexec batch file revision that checks to see if there are
 > any files in drive D: before>it starts windows, and if it does not find
 > any, it instructs the user to>reboot the system .....

 > ..... what I'd like to do is modify this code so that it checks the
 > correct ERRORLEVELs for "Invalid disk drive" versus "file not found"
 > so that the batch file will work even if a disk is not inserted in
 the drive.

 > John, I think you've set yourself an impossible task.  I'm not aware of
 > any way to determine in a batch file if a drive is either valid or
 > ready.  

   Hmm, IF EXIST drive:\NUL should work fine. If the D drive exists,
   assuming it must conform to the MSDOS NUL drive entry method,
   This should handle what he needs.

   Or perhaps more precisely

   IF NOT EXIST D:\NUL GOTO BADDRIVE
   GOTO WIND
   :BADDRIVE
   ECHO REBOOT THE SYSTEM NOW
   GOTO BADDRIVE
   :WIND
   WIN :
   CLS

 > For whatever it's worth, I've attached a simple batch file that'll check
 > and display the ERRORLEVEL.  I use it a lot for the same kind of thing
 > you're

 Thats real nice except we don't permit UUENCODED FILES here.
 Come to think of it, Batch files are off-topic also. Please take this
 thread up in comp.os.mdsos.programmer



Sat, 23 May 1998 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Don't know what the subject is

2. Don't know what the subject is

3. Question regarding Visual Basic and Digital's Visual Batch program

4. Accessing a File's comments or subject field

5. Returning a Batch file's results to ActiveDocument

6. Totally off subject

7. Ok, its a little off the subject

8. Ok, its a little off the subject.

9. Thank you to everyone that responded to off the subject

10. Off Subject (Kind Of)

11. A Bit Off Subject, But.....

 

 
Powered by phpBB® Forum Software