Re: [WIN] GetLogicalDrives returns drives NOT present

new topic     » goto parent     » topic index » view thread      » older message » newer message

Dan Moyer wrote:
> 
> 
> When trying to use:
>  }}}
<eucode>
>        if equal(dir(  aDrive & "://"  ) , -1) then
>           puts(1, "drive not ready")
>         end if 
>  </eucode>
{{{

> to check if a listed drive is "ready" (actually present when some drives
> are reported present when they're not), I get error messages when the
> routine encounters drives that are NOT ready. 
> 
> Searching for how to suppress the error message, I find the following, in 
> what I think I recognize as Pascal code.
> 
> Does it seem like it's likely to do what I want, and does anyone have any 
> suggestions for translating it into Euphoria code?  :)
> 
> Dan
> 
> You can use the Windows API Function SetErrorMode() To suppress the
> Window's critical Error dialog.
> 
> Function IsDriveReady(DriveLetter : char) : bool;
> var
>   OldErrorMode : Word;
>   OldDirectory : String;
> begin
>   OldErrorMode := SetErrorMode(SEM_NOOPENFILEERRORBOX);
>   GetDir(0, OldDirectory);
>   {$I-}
>     Chdir(DriveLetter + ':\');
>   {$I+}
>    If IoResult <> 0 Then
>      Result := False 
>    Else
>      Result := True;
> 
>   Chdir(OldDirectory);
>   SetErrorMode(OldErrorMode);
> End;
> 
> procedure TForm1.Button1Click(Sender: TObject);
> begin
>   If Not IsDriveReady('A') then
>     ShowMessage('Drive Not Ready') else
>     ShowMessage('Drive is Ready');
> End;

That would work too. Suppressing system errors is something you have to do at
some point while developing a piece of software, most importantly a driver, so
the command has to be there. But I certainly wouldn't recommand doing that as
part of normal code operation.
Try perhaps something cleaner using GetLogicalDriveStrings() and
GetVolumePathNamesFromVolumeName() APIs.

CChris

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu