Entwickler-Ecke

Dateizugriff - Standard Verzeichnisse abfragen


derDoc - Mo 17.02.03 22:50
Titel: Standard Verzeichnisse abfragen
Ich hoffe, dass der Post hier hinein gehört, andernfalls sollte er bitte in den entsprechenden Bereich verschoben werden.

Mein Problem ist folgendes:
Ich habe ein Programm, das auf allen Windows Versionen laufen sollte und dabei leider das Windows Verzeichnis benötigt. Da dem Genie bei der Installation des besagten OS kaum Grenzen gesetzt sind möchte ich gerne ein paar Standart Verzeichnisse, wie z.B. das Windows Verzeichnis und unter NT das AllUsersStartUp Folder, herausbekommen.
Was gibt es in dem Fall für Möglichkeiten?


Delete - Mo 17.02.03 23:03


Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
function GetWinDir: String;
const
  UNLEN = MAX_PATH;
var
  Size: DWORD;
begin
  Size := UNLEN + 1;
  SetLength(Result, Size);
  if GetWindowsDirectory(PChar(Result), Size) <> 0 then
    SetLength(Result, Size - 1)
  else
    Result := '';
end;

function GetSysDir: String;
const
  UNLEN = MAX_PATH;
var
  Size: DWORD;
begin
  Size := UNLEN + 1;
  SetLength(Result, Size);
  if GetSystemDirectory(PChar(Result), Size) <> 0 then
    SetLength(Result, Size - 1)
  else
    Result := '';
end;

Für den Rest siehe SHGetSpecialFolderPath im [url=http://www.msdn.mircosoft.com]MSDN[/url].


AndyB - Mo 17.02.03 23:53

Und noch eine kleine Anmerkung zu "Standart". Das hat nichts mit der "Art zu Stehen" zu tun. Es schreibt sich, auch wenn es sehr viele nicht wahr haben wollen, immer noch Standard.


derDoc - Di 18.02.03 16:30

@AndyB: Danke für den Hinweis, ich habe das schon geändert. (War schon spät gestern Abend). :wink:
@Luckie: Danke für deine Beispiele. Ich werde dann mal SHGetSpecialFolderPath benutzen.

Aber nun meine Frage:
Laut dem PlatformSDK ist
Zitat:
SHGetSpecialFolderPath(HWND hwndOwner, LPTSTR lpszPath, int nFolder, BOOL fCreate);


so definiert:

Zitat:
hwndOwner
Handle to the owner window the client should specify if it displays a dialog box or message box.
lpszPath
Pointer to a null-terminated string that receives the drive and path of the specified folder. This buffer must be at least MAX_PATH characters in size.
nFolder
A CSIDL that identifies the folder of interest. If a virtual folder is specified, this function will fail.
fCreate
Indicates if the folder should be created if it does not already exist. If this value is nonzero, the folder will be created. If this value is zero, the folder will not be created.



Quelltext
1:
SHGetSpecialFolderPath(0, aString, CSIDL_WINDOWS, 0);                    


Aber ich bekomme immer nur undefinierter Bezeichner SHGetSpecialFolderPath und CSIDL_WINDOWS.
Welche Unit(s) muss ich mit einbinden?


Delete - Mi 19.02.03 01:09

Was stehen denn im MSDN für Header-Files? Meist heißt die benötigten Delphi Unit gleich.


Tino - Mi 19.02.03 10:56

Du musst die Unit ShlObj einbinden.

Gruß
TINO


derDoc - Mi 19.02.03 20:27

Sollte es von Interesse sein, ich habe das Mal getestet und ein bischen probiert:
Für SHGetSpecialFolderPath benötigt man wie Tino schon schrieb ShlObj.
Leider kann man mit SHGetSpecialFolderPath nicht alle Verzeichnisse bekommen.
Für manche, wie etwa CSIDL_WINDOWS muss man SHGetFolderPath benutzen und benötigt dafür die Unit SHFolder.