I m working with Delphi 7 and I want to find out the path of my .. /All Users/Documents directory.
I came across the following code
uses shlobj, ...
function GetMyDocuments: string;
var
r: Bool;
path: array[0..Max_Path] of Char;
begin
r := ShGetSpecialFolderPath(0, path, CSIDL_Personal, False) ;
if not r then
raise Exception.Create('Could not find MyDocuments folder location.') ;
Result := Path;
end;
It works fine but it does not support CSIDL_COMMON_DOCUMENTS which returns the desired path.
Moreover as per MS CSIDL should no longer be used instead use KNOWNFOLDERID .
And I do need to work this app on multiple OS’s (only windows).
How can I do this ?
Help is appreciated 🙂
In my view there’s nothing wrong with calling
SHGetSpecialFolderPathpassingCSIDL_COMMON_DOCUMENTS. If you need to support XP then you can’t use known folder IDs. You could write code that used known folder IDs on Vista and up, and fell back to CSIDL on earlier systems. But why bother? MS have done that for you withSHGetSpecialFolderPath.