1. You are viewing our forum as a guest. For full access please Register. WindowsBBS.com is completely free, paid for by advertisers and donations.

Detecting a floppy disk from a batch file

Discussion in 'Windows XP' started by PCFarmer, 2008/04/07.

  1. 2008/04/07
    PCFarmer

    PCFarmer Inactive Thread Starter

    Joined:
    2008/04/07
    Messages:
    28
    Likes Received:
    0
    Hi,

    Can anyone tell me if it is possible to determine if a floppy disk is present in the A: drive from a batch file?

    I beleive that at one time it was possible to use the following line:-

    xcopy A:\NULL

    and then use ERRORLEVEL etc. This no longer works in Windows XP (SP2).

    Regards PCFarmer
     
  2. 2008/04/09
    TonyT

    TonyT SuperGeek Staff

    Joined:
    2002/01/18
    Messages:
    9,072
    Likes Received:
    400
    Just using:
    a:\
    will cause the op sys to check the drive for a disk every 1 second.

    You could probably use an IF statement as well, checking the floppy disk for a file you know cannot possibly be there.

    REM detect if disk in floppy drive
    @ECHO OFF
    IF NOT EXIST a:\iexplore.exe
    ECHO No disk in drive, please insert a disk.
    PAUSE
     
    Last edited: 2008/04/09

  3. to hide this advert.

  4. 2008/04/09
    PCFarmer

    PCFarmer Inactive Thread Starter

    Joined:
    2008/04/07
    Messages:
    28
    Likes Received:
    0
    Hi,

    I have tried doing something similar to this but the problem is that if the floppy is not inserted we get a windows dialogue appear.

    PCFarmer
     
  5. 2008/04/09
    TonyT

    TonyT SuperGeek Staff

    Joined:
    2002/01/18
    Messages:
    9,072
    Likes Received:
    400
    It would help if we knew wxhat you were doing w/ the bat file and why you need to check if a disk is in the drive. Let's say you needed to copy the same file all the time using the bat file:

    @ECHO OFF
    xcopy %USERPROFILE%\My Documents\THE-FILE.XXX" "a:\ "
    if ERRORLEVEL == 1 goto ERROR
    :ERROR
    echo Please insert a floppy disk!
    pause
     
  6. 2008/04/10
    PCFarmer

    PCFarmer Inactive Thread Starter

    Joined:
    2008/04/07
    Messages:
    28
    Likes Received:
    0
    Hi,

    I am following a very good Win98 batch file coarse on the internet as a recap for the old days. Part of the coarse uses the:-

    xcopy a:\NUL

    to determine if a floppy drive is present in its drive. I just got to wondering how something this simple would be done using windows xp these days. The answer does not appear to be that simple at all.

    The reason for doing this is part of a backup batch file where both the source and destination are arguments to the backup batch file. It is quite possible to select the A: drive as the destination (or source) and therefore it would be useful to detect if the drive is ready or not without forcing windows dialogue boxes to appear.

    Regards PCFarmer
     
  7. 2008/04/10
    Steve R Jones

    Steve R Jones SuperGeek Staff

    Joined:
    2001/12/30
    Messages:
    12,315
    Likes Received:
    252
    Me thinks - looking at the drive would be the only way to keep windows out of the formula.
     
  8. 2008/04/10
    mflynn

    mflynn Inactive

    Joined:
    2002/08/14
    Messages:
    4,141
    Likes Received:
    9
    OK here is the answer.

    You are gettiing a very low level dos error

    Abort, Retry or Fail that has to be resopnded too.

    Win98 did not have the contol over these low level functions that NT class 32 bit windows has. XP is being "controling" to possibly protect itself from DOS.

    There is some very complex ways to do this using for next loops and ctty etc.

    But a simpler way is to download a program that can handle this error correctly. There are many programs that can handle this and report the errorlevel.

    Download pkzip and copy it to the Windows folder so it will be in the path, or you can put it elsewhere but will need to address its path correctly in the batch.

    Pkzip has an error checking routine that can handle the Abort, Retry....

    SO!
    -------------------------------------------------------------------------
    @echo off

    ::send file that should not exist to a: using Pkzip

    pkzip a:\zzz.zip nul>nul
    if errorlevel 1 goto NODISK

    :: the line above detects there is no drive (errorlevel 1) and routes to NODISK
    :: if the errorlevel is other than 1 there is a disk so it does not go to NODISK
    :: but falls thru to GOTO GOTDISK

    del a:\zzz.zip > nul
    :: since there is a dirive then we actually did create a file on it so the line
    :: above deletes that file

    goto GOTDISK

    :NODISK
    echo You didn't insert a writable disk!
    goto DONE

    :GOTDISK
    echo You put a writable disk in! Good dog!
    goto DONE
    :DONE
    ------------------------------------------------------------------------
    Note the last line above should be
    : DONE
    (without the space) but since it is didrectly ajecent to the colon it is interpeted as a grin:D

    Mike
     
  9. 2008/04/10
    PCFarmer

    PCFarmer Inactive Thread Starter

    Joined:
    2008/04/07
    Messages:
    28
    Likes Received:
    0
    Hi,

    Many thanks for your help. I will download the utility and give this script a go.

    PCFarmer
     
  10. 2008/04/10
    mflynn

    mflynn Inactive

    Joined:
    2002/08/14
    Messages:
    4,141
    Likes Received:
    9
    I jumped the gun!

    Don't bother, I have used this before but it may have been on 2k or a lower sp in XP, but I just tested it again on XP pro sp2 and it failed.

    Sorry I didn't test it again sooner but I was involved with several things when I posted.

    But here is a even simpler way. That I tested.

    Download the below and extract Drvexist.exe copy to Windows so it will be in the path.

    http://www.mahringer.co.at/mwbat1.zip

    use it like this

    -----------------------------------------------------------------------
    @echo off
    drvexist a:
    if errorlevel 1 goto NODISK

    :: the line above detects there is no drive (errorlevel 1) and routes to NODISK
    :: if the errorlevel is other than 1 there is a disk so it does not go to NODISK
    :: but falls thru to GOTO GOTDISK

    goto GOTDISK

    :NODISK
    echo You didn't insert a writable disk!
    goto DONE

    :GOTDISK
    echo You put a writable disk in!
    goto DONE

    :DONE
    pause
    ----------------------------------------------------------------------
    I put the pause above so it would not exit for testing!

    Mike

    PS make sure to correct the Gin as in my last post.
     
    Last edited: 2008/04/10
  11. 2008/04/10
    surferdude2

    surferdude2 Inactive

    Joined:
    2004/07/04
    Messages:
    4,009
    Likes Received:
    23
    Hi Mike, FYI you can tag the box on the posting screen to "disable Smilies in text" and your script will look like this:

    use it like this

    -----------------------------------------------------------------------
    @echo off
    drvexist a:
    if errorlevel 1 goto NODISK

    :: the line above detects there is no drive (errorlevel 1) and routes to NODISK
    :: if the errorlevel is other than 1 there is a disk so it does not go to NODISK
    :: but falls thru to GOTO GOTDISK

    goto GOTDISK

    :NODISK
    echo You didn't insert a writable disk!
    goto DONE

    :GOTDISK
    echo You put a writable disk in!
    goto DONE

    :DONE
    pause
     
  12. 2008/04/11
    PCFarmer

    PCFarmer Inactive Thread Starter

    Joined:
    2008/04/07
    Messages:
    28
    Likes Received:
    0
    Hi Mike,

    Thanks for the download URL, it contains one or two other useful items I can use.

    How do you set ERRORLEVEL from an application, is it simply the value that the main() function returns?

    Regards PCFarmer
     
  13. 2008/04/11
    mflynn

    mflynn Inactive

    Joined:
    2002/08/14
    Messages:
    4,141
    Likes Received:
    9
    It is usually set by the App. In this case 1 means unsucessful which is normal for failure.

    Errorlevel can be from 1-255 and each can mean something else.

    I assume you have tested and it does what you want?

    Mike
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.