Einzelnen Beitrag anzeigen

nuclearping

Registriert seit: 7. Jun 2008
708 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#2

AW: "User" Dokumente Verzeichnis finden

  Alt 11. Mai 2011, 18:28
Über http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx und SHGetSpecialFolderLocation.

Delphi-Quellcode:
{ ************************************************************ }
function GetSpecialPath (AFolder: Integer): String;
{ ************************************************************ }

  { ************************************************************ }
  function PidlToPath (IdList: PItemIdList): String;
  { ************************************************************ }
  begin
    SetLength (Result, MAX_PATH);
    if SHGetPathFromIdList (IdList, PChar (Result)) then
      begin
        SetLength (Result, StrLen (PChar (Result)));
        Result := IncludeTrailingPathDelimiter (Result);
      end
    else Result := '';
  end; // PIdlToPath

  { ************************************************************ }
  function PidlFree (var IdList: PItemIdList): Boolean;
  { ************************************************************ }
  var
    Malloc : IMalloc;
  begin
    Result := False;
    if IdList = nil then
      Result := True
    else begin
           if Succeeded (SHGetMalloc (Malloc)) and (Malloc.DidAlloc (IdList) > 0) then
             begin
               Malloc.Free (IdList);
               IdList := nil;
               Result := True;
             end;
         end;
  end; // PidlFree

var
  FolderPidl : PItemIdList;
begin
  Result := '';
  try
    if Succeeded (SHGetSpecialFolderLocation (0, AFolder, FolderPidl)) then
      begin
        Result := PidlToPath (FolderPidl);
        PidlFree (FolderPidl);
      end;
  except
    Result := '';
  end;
end; // GetSpecialPath

User_Documents_Path := GetSpecialPath(CSIDL_COMMON_DOCUMENTS);
  Mit Zitat antworten Zitat