Solved

[Kylix] How do I determine the home directory?

Posted on 2002-06-09
2
151 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Thread safe  opinion 7 126
creating manifest for my dll that called from activex 6 98
proper way to parse text with delphi 7 99
Working with hours 3 46
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…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

930 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

9 Experts available now in Live!

Get 1:1 Help Now