Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Where to save/read config file? 2

Status
Not open for further replies.

AP81

Programmer
Apr 11, 2003
740
0
0
AU
I am trying to read a file from C:\Documents and Settings\adam called initials.txt. Because these computers log onto a domain, each person has a folder under C:\Documents and Settings\

My problem is this: If I want to save a text file (used as a config file) into a persons homepath (C:\Documents and Settings\username) how would I do so with Delphi?

In msdos you can access the user path using %homepath%. Can I do something similar in Delphi?, e.g:

Code:
procedure TForm1.ReadConfig;
var
  txtFile : TextFile;
begin
  try
    try
      AssignFile(txtFile, [b]'%homedrive%.initials.txt'[/b]); 
      Reset(txtFile);                      
      ReadLn(txtFile, strName);             
      closeFile(txtFile);                    
    except showmessage('error!');
    end;
  finally
    Form1.Caption := strName;          //display initials
  end;
end;

Thanks in advance.




------------------------------------
There's no place like 127.0.0.1
------------------------------------
 
you can read the registry key
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Personal]


Aaron Taylor
John Mutch Electronics
 
Thanks aaronjme. Would you know how to get the 'my documents' path (seeing as each person has a persitent 'My Documents' directory stored on the fileserver?




------------------------------------
There's no place like 127.0.0.1
------------------------------------
 
that key is the path to the users my documents folder, regardless of what the directory is called or where its located.

for example it might be d:\daves files or h:\daves files.
h:\ being the file server.

or is your question asking how to retrieve the key?

Aaron Taylor
John Mutch Electronics
 
Hey there
Code:
uses ShlObj;
...
function GetDefaultSavePath(): String;
var
  APath      : pChar;
begin
  GetMem(APath, MAX_PATH + 1);
  SHGetSpecialFolderPath(Application.Handle, APath, CSIDL_PERSONAL, False);
  SetString(Result, APath, lstrlen(APath));
  Result := Trim(Result);
  FreeMem(APath);
end;

--- McMerfy
 
Yep, but in this case I don't need to know where the reg key is located ;)

--- McMerfy
 
Thanks McMerfy.

Both are good.




------------------------------------
There's no place like 127.0.0.1
------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top