Solved

Detect whether your app is on hard drive

Posted on 2004-04-22
6
257 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
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…

751 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