Solved

Detect whether your app is on hard drive

Posted on 2004-04-22
6
254 Views
Last Modified: 2010-04-05
Hi! Could someone tell me how to detect whether one's program is on a writable media (i.e. hard drive) or non - writable (i.e. CD ROM or Write protected floppy) without error messages.

P.S: I tried saving a text file and checking if it exists - this only produces errors!

Thanks :-)
0
Comment
Question by:siwiher
  • 3
  • 2
6 Comments
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10891345
Did you try wrapping your save in a try accept block, capturing the exception and raising a message if the write fails.

Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10891389

 try
 //save file
 except //on some error
 //show message or raise exception
 end


I dont know exactly how you are savubg your texr file (possible post that portion of code)

Shane
0
 

Author Comment

by:siwiher
ID: 10891471
hi this is the code i'm using:

memo1.Lines.SaveToFile('check.txt');
if fileexists('check.txt') then memo1.Text := 'Writable' else memo1.Text := 'Read Only';
deletefile('check.txt');
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 17

Accepted Solution

by:
mokule earned 125 total points
ID: 10891515
Hi
You can check like this

  if GetDriveType(PChar(ExtractFileDrive(Paramstr(0)))) <> DRIVE_CDROM then


---------
  DRIVE_UNKNOWN = 0;
  DRIVE_NO_ROOT_DIR = 1;
  DRIVE_REMOVABLE = 2;
  DRIVE_FIXED = 3;
  DRIVE_REMOTE = 4;
  DRIVE_CDROM = 5;
  DRIVE_RAMDISK = 6;
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10891564
I can't seem to figure out exactly what you are trying to do from your code....

(Where does check.txt exist, in your application folder?)

 try
 if not FileExists('check.txt') then
  Memo1.Lines.SaveToFile('check.txt');
 else
  deletefile('check.txt');
except
 Memo1.Lines.Text:= 'Error saving file';
end;


Shane
0
 

Author Comment

by:siwiher
ID: 10891676
Mokule: It worked like a charm thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now