Solved

Detect whether your app is on hard drive

Posted on 2004-04-22
6
256 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

821 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