Checking To See if a Drive is Empty |
(Windows Only)
|
DriveReady application required |
NOTE: This tip requires the third party command line utility DriveReady, which can be found at http://www.jsifaq.com/dl/drvready.zip. |
> Putting "the drives" or "the volumes" will give you a list of available
> drives with media in MacOS. In win95, 98 and XP you get a list of all
> mechanically attached equipment. If you then do a "If there is
> a:/mydisk/myfolder then..." line of code you get some whirling and
> clicking in 95 and 98 - but no error message from an empty floppy drive.
> In XP if you check for a folder or file in a drive that does not contain
> media - you get a system error message from XP.
>
> Is there any way in XP (and 95/98) to check to see if there is media
> in a drive without getting an error message?
You can use the DriveReady command line utility at http://www.jsifaq.com/dl/drvready.zip. It must be run in a batch file though, so create a batch file like "testa.bat" and put the following in it:
Then call the batch file from thedrvready.exe a: /q @echo %ERRORLEVEL%
shell()
command in MC. If it returns a 1,
there is a disk in the drive. If it returns a 0, there is no disk in the
drive. It does it silently, so there's not error dialogs or "please put in a
disk" dialogs.
In order to call this from MetaCard or Revolution, you can "cd" to the directory where DRVREADY.EXE is located, and then call the batch file (called "checkdrv.bat" in the example below). Here’s an example:
on mouseUp answer folder "Pick the location of DRVREADY:" if it <> "" then if DriveReady(it) then -- floppy is in the drive else -- no floppy is in the drive end if end if end mouseUp function DriveReady pPath replace "/" with "\" in pPath -- convert to proper slashes set the hideConsoleWindows to true get shell("cd " & pPath & " & checkdrv.bat") if last line of it = 0 then -- no floppy in drive return false else -- floppy in drive return true end if end mouseUp
Update 2/13/04:
Note: To clarify the update below, XP does NOT show an alert only if you have Service Pack 1 installed.
Otherwise, it appears that this approach does not work properly in XP without the service pack (odd results from
DriveReady are occurring).
Update 8/10/03:
Note: It turns out that Windows XP does NOT show an alert if there is no media in the drive, so you
don't need DriveReady for a Windows XP test.
Posted 12/23/2002 by Ken Ray to the MetaCard List
Updated 1/18/2003 by Ken Ray
Updated 8/10/2003 by Ken Ray
Updated 2/13/2004 by Ken Ray