How To Detect if Diskdrive Contains a Floppy

This article explains how to detect if a diskette is in the disk drive on NT based systems (w2k, XP)

Windows has the habit of requesting the user to insert a floppy. Normally this would not be a problem, but suppose you want to know if a floppy is in the drive or not.

There are various ways to detect a floppy disk, an easy method is the function DirectoryExists which is declared in filectrl.pas.
If a floppy is there, it succeeds. If not, the function will only fail after the user has pressed 'Cancel' to the question wether he/she wants to insert a floppy disk.

This behaviour can be altered by (temporary) setting the windows error behaviour when calling an api. By setting this to 'critical only', we effectively prevent windows from querying the user.

Here is an example function that checks if a floppy is in drive A.

uses filectrl;
function IsFloppyInDrive:Boolean;
var om: Integer; //OlderrorModus

  Result := DirectoryExists ('A:\');
  SetErrorMode (om);


Share this article!

Follow us!

Find more helpful articles: