[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Find directory of "My Documents" or local equivalent

Posted on 2007-07-21
9
Medium Priority
?
1,059 Views
Last Modified: 2008-02-01
I need to specify a subdirectory relative to the "My documents" path. I'd like to do that with hardcoding the path. Initially I tried
Type DirPath = '%HOMEDRIVE%%HOMEPATH%\My Documents\Admin\logs\' ;
Well, I get "illegal filename" when using the %HOMEDRIVE% stuff. I cant use the GetEnviromentVariable (as recomended in many answers on EE) as this is Delphi5 and it isnt in help (or is there a unit that isnt covered in Help?) so I assume that is D6 or above.
Also, what is the trick to get the name of "My Documents" ? It is "Dokumenter" on Danish Windows as an example (and I did discover it in the registry one time long ago) The whole path for MyDocuments would do nicely (and thus ellminate the need for HOMEDRIVE/PATH)
Delphi 5, running on Windows XP
0
Comment
Question by:Msquare
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 10

Assisted Solution

by:dinilud
dinilud earned 336 total points
ID: 19539220
0
 
LVL 11

Accepted Solution

by:
ZhaawZ earned 664 total points
ID: 19540182
Not sure about Delphi5, but there are a lot of things that are not in the help of Delphi 6 Personal :)



unit Unit1;

interface

uses
  Windows, Messages, Classes, Controls, Forms, Dialogs, ShlObj;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
  path : array [0..255] of char;
begin
SHGetSpecialFolderPath(0, @path, CSIDL_PERSONAL, false);
ShowMessage(path);
end;

end.
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 19540246
ZhaawZ, why do you provide the same solution as dinilud?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:ZhaawZ
ID: 19540281
It's not really the same. It may seem similar, but different functions are used. I think it's good to know that there are more than 1 ways to get the result, isn't it?

I'm sorry if I offended you with that - I didn't want to...

The sollution you gave uses SHGetSpecialFolderLocation() AND SHGetPathFromIDList() functions to get the past, while it's possible to use one function instead - SHGetSpecialFolderPath().
0
 
LVL 11

Expert Comment

by:ZhaawZ
ID: 19540283
... to get the path*, while ...
0
 
LVL 2

Author Comment

by:Msquare
ID: 19540518
Thanks to both. I choose the latter version as it seems shorter. Also had to adapt the answer http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_20324781.html to get it all tied up. It works now.
I'll split this 1:2 (if I can)
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 19541919
ZhaawZ, I never suggested a solution.
It just seems too happen so often on EE that people give a duplicate answer just to get the points. It's very annoying.
0
 
LVL 11

Expert Comment

by:ZhaawZ
ID: 19541970
Sorry, didn't notice that sollution was from dinilud, not from you (I was too sleepy probably).

About the answer - as I said, it's not the same...
0
 
LVL 2

Author Comment

by:Msquare
ID: 19543286
Well, not part of this question ... but I just note that the "FAQ/Rulebook" says the process in EE is to receive several answers and the questioner gets to choose the best one. :-)
 http://www.experts-exchange.com/help.jsp#hi38
If you want to discuss if the answers are too close to each other ... (do it somewhere else on this site?)

I do have a microscopic followup ... how do I find more "goodies" in ShlObj ? OK, ok, I looked in the source for the unit, and it clearly requires a Windows SDK or suchlike. Never mind, I'll ask in a seperate question if/when I have the need/time to go down that path.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Integration Management Part 2
Screencast - Getting to Know the Pipeline
Suggested Courses

867 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