Solved

[Kylix] How do I determine the home directory?

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

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…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

18 Experts available now in Live!

Get 1:1 Help Now