Description: If your program checks either the floppy or CD-ROM drive for a file, the drive makes a lot of racket and generally annoys the user. Plus, Windows then displays an old Win 3.x looking dialog indicating the failure.
TO avoid this, we can set the global Windows error mode to critical which turns off these error displays. It also checks the drive without causing it to make a lot of racket.
Use the following function anytime you want to check a drive to see if it is empty or not. Simply pass in the drive letter as a character.
function DiskInDrive(lw: Char): Boolean; var áásRec: TSearchRec; ááres: Integer;
begin ááResult:= False; ááSetErrorMode(SEM_FAILCRITICALERRORS);áá
{$I-} ááááres := FindFirst(lw + ':\*.*', faAnyfile, SRec ); ááááFindClose(SRec);áá {$I+} Result := Res = 0; end;
------------------ Larry J. Rutledge
Programmer / Analyst Prestwood Software & Consulting 7525 Auburn Blvd., #8 Citrus Heights, CA 95610
Old UBB Archived Link: [URL=http://www.prestwood.com]www.prestwood.com[/URL]
Serving your IT needs since 1984!
[This message has been edited by Larry Rutledge (edited December 27, 2000).]
This works well enough if you have a floppy drive 'plugged in', but if there is not a floppy drive present it can take up to 20 seconds before leaving the routine. Is there a quick method for determining if a floppy drive or CD Drive for that matter are 'physically' plugged in.
Member subscribes to this thread but email is NOT VERIFIED.
Email Not Verified!
Once email is verified, we will review and approve the account.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html,
social networking links, message board signature, company profile, etc.
Member subscribes to this thread but email is NOT VERIFIED.
Email Not Verified!
Once email is verified, we will review and approve the account.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html,
social networking links, message board signature, company profile, etc.
It appears I have been too hasty in saying the problem has been sorted. ok, GetDriveType tells me that the floppy is removable and the CD is a CD drive, but it does not tell me if they are physically plugged in e.g. external floppy drive. Although I can use DirectoryExists but I have to wait for about 20 seconds for each drive to be checked. Ideally there should only be a wait of about 5 seconds.
Member subscribes to this thread but email is NOT VERIFIED.
Email Not Verified!
Once email is verified, we will review and approve the account.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html,
social networking links, message board signature, company profile, etc.
Sorry, but that takes the same amount of time (20 seconds), the same time as DirectoryExists. This is really bizarre, there must be a way to tell if removable drive is removed in a few seconds!!
Member subscribes to this thread but email is NOT VERIFIED.
Email Not Verified!
Once email is verified, we will review and approve the account.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html,
social networking links, message board signature, company profile, etc.
First, you should always restore the old error mode after you are done doing an operation that required you to change it. Second, you should check for the existance of the logical drive before attempting to find out if a disk is in the drive. Third, you should use a function like GetDiskFreeSpace instead of FindFirst because it returns much faster.
The following is a better implementation:
function DiskInDrive (Drive : Char) : Boolean;
var OldErrorMode : Integer; Drives : LongWord; Temp : Cardinal;
begin Result := False; OldErrorMode := SetErrorMode(SEM_FAILCRITICALERRORS); try Drives := GetLogicalDrives; if Drives shr (Ord(UpCase(Drive))-65) and $00000001 = 1 then begin Result := GetDiskFreeSpace(PChar(Drive+':\'),Temp,Temp,Temp,Temp); end; finally SetErrorMode(OldErrorMode); end; end;
--- William Pantoja Consultant/Software Engineer ForceOne Technologies, Inc.
As a post-script, the function GetDriveType can be used to determine what drive type is (unknown, no root directory, fixed, removable, CD-ROM, RAM drive, or network drive).
--- William Pantoja Consultant/Software Engineer ForceOne Technologies, Inc.