Solved

Detect whether your app is on hard drive

Posted on 2004-04-22
6
258 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
Technology Partners: 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month4 days, 15 hours left to enroll

635 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