-Collapse +Expand
Delphi
Search Delphi Group:

Advanced
Delphi To/From
To/FromCODEGuides
Delphi Store
PRESTWOODSTORE

Prestwood eMagazine

September Edition
Subscribe now! It's Free!
Enter your email:

   ► MB LobbyPascal and Delphi Coding BoardDelphi News / Other Topic   Print This     

Tip: Check for disk in drive

Tip: Check for disk in drive in Delphi News / Other topic (part of our Pascal and Delphi Coding group).

Quick Search: Tip Check   Tip Check disk  
Larry J. Rutledge
Prestwood IT
Citrus Heights, CA USA
Version Info: All Versions.

Category: File System

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).]
Larry J. Rutledge

Analyst

Prestwood Software

www.prestwood.com
 Posted 26 years ago (Thread Starter)
Comment Quote
About Larry J. Rutledge
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.
About Larry J. Rutledge
I worked for Prestwood Software as a Delphi developer from 1997 through 2002. During that time I enjoyed working with Mike Prestwood and the other developers at Prestwood.

Post ID #369, 8 replies
Thread Started 12/27/2000 9:11:00 AM
View Counter=3240
Last Reply Posted 9/4/2001 1:39:00 PM)
Location=Citrus Heights, CA USA 
Joined=26 years ago   MB Posts=73   KB Posts=9  
spj
Southern England, UK
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.

Please help....
 Posted 25 years ago
Comment Quote
About spj
Visit Profile
Membership pending.
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.

Post ID #3573 (Level 1.1)  Reply to 369
Thread Started 9/3/2001 3:50:00 AM
View Counter=2
Location=Southern England, UK  
Joined=25 years ago   MB Posts=13  
spj
Southern England, UK
Thanks, GetDriveType seems to have done the trick, I tried DirectoryExists below and that came back in about 20 seconds.

 Function CheckDrive(Drive: Char);
begin
Result := DirectoryExists(Drive + ':\');
end;


Once again, thanks
 Posted 25 years ago
Comment Quote
About spj
Visit Profile
Membership pending.
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.

Post ID #3579 (Level 1.2)  Reply to 369
Reply Posted 9/4/2001 5:51:00 AM
Location=Southern England, UK  
Joined=25 years ago   MB Posts=13  
spj
Southern England, UK
Whoops,

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.

Sorry, any more ideas greatfully received. Big Grin!
 Posted 25 years ago
Comment Quote
About spj
Visit Profile
Membership pending.
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.

Post ID #3582 (Level 1.3)  Reply to 369
Reply Posted 9/4/2001 6:40:00 AM
Location=Southern England, UK  
Joined=25 years ago   MB Posts=13  
spj
Southern England, UK
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!!
 Posted 25 years ago
Comment Quote
About spj
Visit Profile
Membership pending.
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.

Post ID #3587 (Level 1.4)  Reply to 369
Reply Posted 9/4/2001 8:07:00 AM
Location=Southern England, UK  
Joined=25 years ago   MB Posts=13  
William Pantoja
Woodinville, WA, USA
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.

 Posted 25 years ago
Comment Quote
About William Pantoja
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.

Post ID #3576 (Level 1.5)  Reply to 369
Reply Posted 9/4/2001 4:08:00 AM
Location=Woodinville, WA, USA  
Joined=25 years ago   MB Posts=163   KB Posts=1  
William Pantoja
Woodinville, WA, USA
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.

 Posted 25 years ago
Comment Quote
About William Pantoja
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.

Post ID #3577 (Level 1.6)  Reply to 369
Reply Posted 9/4/2001 4:14:00 AM
Location=Woodinville, WA, USA  
Joined=25 years ago   MB Posts=163   KB Posts=1  
William Pantoja
Woodinville, WA, USA
Check out my first message for determining whether a drive exists.

---
William Pantoja

Consultant/Software Engineer
ForceOne Technologies, Inc.

 Posted 25 years ago
Comment Quote
About William Pantoja
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.

Post ID #3583 (Level 1.7)  Reply to 369
Reply Posted 9/4/2001 6:49:00 AM
Location=Woodinville, WA, USA  
Joined=25 years ago   MB Posts=163   KB Posts=1  
Most Recent Post
William Pantoja
Woodinville, WA, USA
Yes. Use the GetLogicalDrives function. If a removable drive is removed, it's cooresponding logical drive will be removed.

The function in my first message tells if removable MEDIA is in the drive. This always takes longer because the drive has to spin up.

---
William Pantoja

Consultant/Software Engineer
ForceOne Technologies, Inc.

 Posted 25 years ago
Comment Quote
About William Pantoja
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.

Post ID #3598 (Level 1.8)  Reply to 369
Reply Posted 9/4/2001 1:39:00 PM
Location=Woodinville, WA, USA  
Joined=25 years ago   MB Posts=163   KB Posts=1  

Revive Thread!

Add a comment to revive this old thread and make this archived thread more useful.

Write a Comment...
Full Editor
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1142A1
Enter key:
Icon: A Post    Thread    Idea    Important!    Cool    Sad    No    Yes    Includes a Link...   
Thread #369 Counter
3240
Since 4/2/2008
Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2026 Prestwood IT Solutions.   [Security & Privacy]