DiskScan

Started by mhall, December 10, 2013, 10:48:15 PM

Previous topic - Next topic

mhall

Hi All,

A hopefully simple question. I'm currently writing an interface that needs to present a user with a list of available drives (both fixed and removable type) and I'm using DiskScan to generate the list of drives. However, DiskScan includes present but "empty" or inaccessible drives. Specifically there is a built in CF/SD type reader on this system which has several media slots and for which drive letters are reserved. But there is no media in the reader slots (and never will - we don't use those media types).

If a user selects any of the drives that have no media in them and any of my code tries to operate against that drive selection, I get a fatal error that terminates the script.

I was hoping that diskExist() might let me determine that the drive was unavailable, but it doesn't. The drive is present, simply has no media! I have also tried changing errorMode to @OFF and doing both a dirChange() and a logDisk() with the selected letter to check the return value ... but even with errorMode set to @OFF, the script crashes.

Does anyone have any suggestions as to how I might go about filtering these drives out of my list?

Thanks!
Micheal


snowsnowsnow

What as you using as the parameter in the DiskScan() call?

The documentation lists the meanings of the bits in the passed parameter.  It looks like if you leave out the "1 bit", it will ignore "removable" drives.  I think this is what you are looking for.

mhall

Hi Snow,

Unfortunately, there is one drive letter in the list that I do need access to.

I've tried bits 1, 2 and 64. The drives appear in the list of removeable drives (1) and USB bus drives (64).

What I need is a way to enumerate removeable drives which have media in them (and are therefore validly accessible at runtime) or some way to distinguish between a removeable drive with no media and one with media). Perhaps an enhancement to the DiskExist function so that it returns a 1 if the disk is valid and -1 if the disk is valid but with no media.

And where I really need it is WebBatch. The interface I'm working on is a web based one and it works great, except for the this one gotcha that causes the server to cough up errors at me.

In the meantime, I can probably store some configuration listing the reserved drive letters ... but I don't like that idea much. In fact, I hate it.  :(

Regards,
Micheal

snowsnowsnow


I know there is some semi-obscure function which can be used, as sort of a side-effect, as a "Test for drive ready".

I don't really have the ability to test it at the moment, but I *think* DiskFree() can do it.  If that returns an error, then you know the drive is "not ready".

The trick in all this is that you want a function that returns quickly on an error condition, i.e., that doesn't sit there and grind away for a while and/or generate some weird system error (like the classic old DOS "critical error handler").

Maybe someone else will chime in as to which function I am thinking of.  I know I used this once long ago...



mhall

Ha! That looks like it will do it. Thanks!

It returns 0 for those empty drives, which is perfect.

Thanks again.

Regards,
Micheal

Deana

Quote from: snowsnowsnow on December 11, 2013, 04:12:47 AM

I know there is some semi-obscure function which can be used, as sort of a side-effect, as a "Test for drive ready".

I don't really have the ability to test it at the moment, but I *think* DiskFree() can do it.  If that returns an error, then you know the drive is "not ready".

The trick in all this is that you want a function that returns quickly on an error condition, i.e., that doesn't sit there and grind away for a while and/or generate some weird system error (like the classic old DOS "critical error handler").

Maybe someone else will chime in as to which function I am thinking of.  I know I used this once long ago...

I wonder if you are thinking of the WILX extender function xDriveReady. It can be used to check whether the drive is ready. However, I like the suggestion of using DiskFree ( clever ).


Code (winbatch) Select
; DISKFREE METHOD
drives = DiskScan( 1|2|64 )
count = ItemCount( drives, @TAB )
drivesready = ''
for i = 1 to count
   thisdrive = ItemExtract( i, drives, @TAB )
   ret = DiskFree( thisdrive )
   if ret == 0 then continue
   if drivesready =='' then drivesready = thisdrive
   else drivesready = drivesready : @TAB : thisdrive
next
AskItemList('Drives Ready', drivesready, @TAB, @SORTED, @SINGLE, @TRUE )
Exit




Code (winbatch) Select
; WILX EXTENDER xDriveReady
AddExtender( 'wilx44i.dll', 0, 'wilx64i.dll'); Load Appropriate Extender

drives = DiskScan( 1|2|64 )
count = ItemCount( drives, @TAB )
drivesready = ''
for i = 1 to count
   thisdrive = ItemExtract( i, drives, @TAB )
   ret = xDriveReady( thisdrive )
   if ret == 0 then continue
   if drivesready =='' then drivesready = thisdrive
   else drivesready = drivesready : @TAB : thisdrive
next
AskItemList('Drives Ready', drivesready, @TAB, @SORTED, @SINGLE, @TRUE )
Exit



Deana F.
Technical Support
Wilson WindowWare Inc.

mhall

Thanks Deana,

That first example, using DiskFree is pretty much exactly how I wound up implementing it!

Regards,
Micheal

snowsnowsnow

Now that I think about it, I think I was thinking of the xDriveReady() function.

But I must have done it the other way (DiskFree()) as well.  Note that what's really cute about using DiskFree() is that you don't need to code an error handler.  It "Just Works".

BTW, I wonder if DiskSize() would work.  That would avoid the (admittedly unlikely) ambiguity between there really being no free space on the drive and the drive not being ready (as both would return 0).  If DiskSize() returns 0, it can only mean "not ready" as I don't think anyone would bother manufacturing a disk device with a capacity of zero.

Deana

Yes, I would think that DiskSize should work just as well as DiskFree and I agree that it would probably be the better option because of the free space ambiguity.
Deana F.
Technical Support
Wilson WindowWare Inc.