Solved

[Kylix] How do I determine the home directory?

Posted on 2002-06-09
2
153 Views
Last Modified: 2010-04-04
How can I determine programatically what the current "home" directory is?  I tried this:

procedure TForm1.Button1Click(Sender: TObject);
begin
  with TStringList.Create do
  begin
    Clear;
    Add('This is a test!');
    SaveToFile('~/TestFile.txt');
    Free;
  end;
end;
In UNIX/Linux, the "~/" should represent the user's home directory.  However, Kylix doesn't seem to see it that way.  I then tried replacing the "~/TestFile.txt" with "/home/edsteele/TestFile.txt" and that worked.  The problem is that if another person runs the program, this won't be their home directory.

The value of the current user's home directory is stored in an environment variable called "HOME".  Barring a better solution, how can I read the value of environment variables?

Thanks,
Eric
0
Comment
Question by:edsteele
2 Comments
 
LVL 17

Accepted Solution

by:
inthe earned 100 total points
ID: 7066183
hi,
here are a couple of examples i found :

//to read the environment var
getenv("HOME")


// to read it from etc/passwd
procedure TForm1.Button1Click(Sender: TObject);
var
  ppwd :PPasswordRecord;
begin
  ppwd := getpwuid( getuid() );
  Caption := ppwd^.pw_dir;
end;
0
 
LVL 1

Author Comment

by:edsteele
ID: 7070878
After your direction, I found the function I was looking for.  It is actually called GetEnvironmentVariable().  I didn't get a chance to try the second solution yet.  Thanks for the help, I'm sure I will have more.  :)

Eric
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

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