Solved

Detect whether your app is on hard drive

Posted on 2004-04-22
6
253 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 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

12 Experts available now in Live!

Get 1:1 Help Now