Solved

[Kylix] How do I determine the home directory?

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
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…

739 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