Mirror

How to determine if a formatted disk is in a drive (Views: 710)


Problem/Question/Abstract:

I am trying to create a backup-routine for one of my applications. For that purpose I need a routine to test if there is a formatted disk in the disk-drive.

Answer:

There are two routines in the Object Pascal Language that can be used to determine if a formatted diskette is in a drive, as both return the same results if there is not a diskette in the drive. "DiskFree" and "DiskSize". You need to disable Windows error handling before using them or else Windows will display an error window and cause the functions to return invalid results.


procedure TForm1.Button1Click(Sender: TObject);
var
  emode: word;
begin
  emode := SetErrorMode(SEM_FAILCRITICALERRORS);
  edit1.text := IntToStr(Diskfree(1));
  SetErrorMode(emode);
end;


If DiskFree returns "-1" then there is not a formatted diskette in the drive.

<< Back to main page