All Things WinBatch > WinBatch

Best way to determine if a removable disk is present in drive.

(1/3) > >>

snowsnowsnow:
I have a USB card reader attached to my system, as drive Q:.  So, the WB function:

DiskExist("Q:")

return TRUE (1) regardless of whether or not there is an actual memory card inserted.

My goal is to be able to tell whether or not a memory card is inserted.  Most other functions that I've tried (such as DirExist()) cause a low-level error box to pop up, saying that the disk is not in the drive and giving my options "Cancel", "Try Again", and "Continue" (all of which seem to be equivalent in meaning).  Obviously, I don't want that box to come up.  And I believe that the normal error trapping routine can't stop this box from coming up.

However, I have found that using DiskVolInfo() in combination with an error trap, does work.

That is, I do:

IF udsTry(`DiskVolInfo("Q:",1)`,0,0) == "0" THEN goto No_Disk_In_Drive

udsTry is a function that sets up an IC(73) error trap and returns 0 if the evaluation of the passed in statement fails.

So, to be clear, this works, but I'm wondering if there isn't a better way.  I seem to remember doing this a long time ago, and it seemed like one of the other functions did this directly (without requiring an error trap).  Can anyone help me out on this?

Again, just to summarize, I remember having dealt with this in the past, and I have a vague memory of their being some direct function (like DriveReady() or something like that) that does it.  But I can't recall it now...

td:
The message box you referred to is brought to by your friendly local operating system, of course.  It is not a WinBatch message box or dialog. 

You may be thinking of the xDriveReady function which is provided by the Wilx extender.  The help file states that it's purpose is to "Checks whether the drive is ready indicating that there is a disk in the drive."

snowsnowsnow:

--- Quote from: td on April 03, 2017, 12:58:46 pm ---The message box you referred to is brought to by your friendly local operating system, of course.  It is not a WinBatch message box or dialog.
--- End quote ---
Yep.  That's why I referred to it as "low level" - I was pretty sure it was coming from the OS (or something similarly beyond WB's control).

Interesting, though, that DiskVolInfo() doesn't seem to cause it to be invoked.


--- Quote ---You may be thinking of the xDriveReady function which is provided by the Wilx extender.  The help file states that it's purpose is to "Checks whether the drive is ready indicating that there is a disk in the drive."

--- End quote ---

I think we have a winner!  Now that you mention it, I'm pretty sure that's the one I used to use.
Thanks for refreshing my memory.

FWIW, I'll probably continue to use the method I am using (with DiskVolInfo()) - at least until I have occasion to do a serious overhaul of the code.

td:

--- Quote from: snowsnowsnow on April 03, 2017, 02:38:01 pm ---
Yep.  That's why I referred to it as "low level" - I was pretty sure it was coming from the OS (or something similarly beyond WB's control).

Interesting, though, that DiskVolInfo() doesn't seem to cause it to be invoked.

--- End quote ---

The function does display the message for optical and floppy drives or at least it should according to MSFT.  If it does not for other devices, you will have to ask MSFT why. 

There is a way to suppress the message box in a WIL script using a couple of DllCalls. 


--- Quote ---I think we have a winner!  Now that you mention it, I'm pretty sure that's the one I used to use.
Thanks for refreshing my memory.

--- End quote ---

I have never tried xDriveReady on a device other than an optical or floppy drive.


--- Quote ---FWIW, I'll probably continue to use the method I am using (with DiskVolInfo()) - at least until I have occasion to do a serious overhaul of the code.

--- End quote ---

You asked.

snowsnowsnow:

--- Quote from: td on April 04, 2017, 06:51:42 am ---
--- Quote from: snowsnowsnow on April 03, 2017, 02:38:01 pm ---
Yep.  That's why I referred to it as "low level" - I was pretty sure it was coming from the OS (or something similarly beyond WB's control).

Interesting, though, that DiskVolInfo() doesn't seem to cause it to be invoked.

--- End quote ---

The function does display the message for optical and floppy drives or at least it should according to MSFT.  If it does not for other devices, you will have to ask MSFT why. 
--- End quote ---
Interesting.  I guess I'll have to take it up with them.


--- Quote ---There is a way to suppress the message box in a WIL script using a couple of DllCalls. 
--- End quote ---
Very interesting.  Care to share?


--- Quote ---
--- Quote ---I think we have a winner!  Now that you mention it, I'm pretty sure that's the one I used to use.
Thanks for refreshing my memory.

--- End quote ---

I have never tried xDriveReady on a device other than an optical or floppy drive.
--- End quote ---
You still have floppy drives???


--- Quote ---
--- Quote ---FWIW, I'll probably continue to use the method I am using (with DiskVolInfo()) - at least until I have occasion to do a serious overhaul of the code.

--- End quote ---

You asked.

--- End quote ---
Indeed I did.  And I am grateful for your responses.  I'm sure that using xDriveReady() is the best way to do it.  I'm just being lazy in not wanting to change my code...

Navigation

[0] Message Index

[#] Next page

Go to full version