***************************************************************** * Neveprise Inc. Delphi FAQ * ***************************************************************** * Section: Files Topic: Disk presence * * Created: July 27th, 1999 Revised: July 27th, 1999 * * Updates: www.neveprise.de Info: support@neveprise.de * ***************************************************************** Q: How can I check if a disk is inserted in a drive? A: To do it, we just have to perform an I/O operation on the target drive, e.g. changing the directory. Normally this would cause an error, and that is what we need: if an error occurs, we know that the drive is not ready (cos we change to the root dir, otherwise it could mean that the directory does not exist). The only problem is that an error also causes a dialog box informing the user, so we have to supress it: function IsDriveReadyH(Drive: char): boolean; var OldErrorMode : Word; OldDirectory : string; begin //remind old error mode and tell windows not to display errors OldErrorMode := SetErrorMode(SEM_NoOpenFileErrorBox); GetDir(0, OldDirectory); //remind old / actual path and drive {$I-} //just to go sure (compiler directive: no error msg) ChDir(Drive+':\'); //go to root of drive to check {$I+} if IoResult<>0 then Result:=false else Result:=true; //above: =0 means, no input/output action error occured ChDir(OldDirectory); //go back to our previous location SetErrorMode(OldErrorMode); //and set original error mode end; Blazko