How to avoid the "Drive A Not Ready" error (Views: 100)


How to avoid the "Drive A Not Ready" error


When your program accesses drive 'A', it would be handy to intercept the 'Drive Not Ready' system error message. You can create your own generic function to test any drive letter.

function DiskInDrive(Drive: Char): Boolean;
  ErrorMode: word;
  Drive: = UpCase(Drive);
  if not (Drive in ['A'..'Z']) then
    raise EConvertError.Create('Not a valid drive ID');
  ErrorMode := SetErrorMode(SEM_FailCriticalErrors);
    if DiskSize(Ord(Drive) - $40) = -1 then
      DiskInDrive := False
      DiskInDrive := True;

Your function forces the passed drive letter to uppercase and assures it is a valid drive. Then you turn off the system error reporting and perform a disk operation. Your function will return True indicating the disk is present or False if there was an error. The last bit of housekeeping is to turn on the system error reporting.

<< Back to main page