Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

[Kylix] How do I determine the home directory?

Posted on 2002-06-09
2
Medium Priority
?
160 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 300 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

618 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