Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check for floppy disk presence at form create

Status
Not open for further replies.

LEICJDN1

Technical User
Nov 27, 2002
201
GB
How can I check there is a floppy disk present before starting main app, so I can then allow user to elect to change file path or insert floppy before carrying on. Windows throws up a standard error if no floppy present when attempting to write file but would be neater to check first and handle errors myself.

Thanks.
 
Hi

Do this:

procedure TForm1.Button1click(Sender : TObject);
begin
if not directoryexists('a:\') then
MessageDlg('There is no floppy present',mtError,[mbOk],0)
else
{ use the drive to write files to it }
end;

-Kudel
 
Thanks.

However, I cannot get it to work with my current setup.
The target file is polled form a Teditbox.text as a string.
How can I extract the drive data from the string, check to see if it is the A drive referred to, and if so, use your above code to force a message if no floppy present? (I do this as the file can be anywhere and not just on a floppy).

Thanks again!
 
Found Extractfiledir which did the job so thanks to Kudel another problem solved.

Have now posted another though!!

Cheers.

JDN
 
The directory exists will still kick out a windows error in Win 2000/xp. You can use this to check on the a:\ (or other drive) without showing the error:

function IsDiskInDrive(ASTR_Drive:char):boolean;
var
ErrorMode:word;
begin
ErrorMode := SetErrorMode(SEM_FailCriticalErrors);
try
result := DirectoryExists(ASTR_Drive + ':\');
finally
SetErrorMode(ErrorMode);
end;
end;
Brian
"There are 2 kinds of people in the world, those that divide people into two groups and those that don't. I belong to the second group." - tag line I stole
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top