Einzelnen Beitrag anzeigen

Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.685 Beiträge
 
Delphi 11 Alexandria
 
#9

AW: Groß/Kleinschreibung (Pfad) Original erhalten?

  Alt 19. Aug 2018, 00:40
Nun habe ich eine Lösung.
Delphi-Quellcode:
uses
  ActiveX, ShlObj, SHDocVw, ComObj;

function PathToPIDL(const Path: string): PItemIDList;
const
  SFGAO_STREAM = $00400000;
var
  Count: ULONG;
  Attributes: ULONG;
  ShellFolder: IShellFolder;
begin
  OleCheck(SHGetDesktopFolder(ShellFolder));
  Attributes := SFGAO_FOLDER or SFGAO_STREAM;
  OleCheck(ShellFolder.ParseDisplayName(0, nil, PWideChar(WideString(Path)), Count, Result, Attributes));
  if not ((Attributes and SFGAO_FOLDER = SFGAO_FOLDER) and (Attributes and SFGAO_STREAM <> SFGAO_STREAM)) then
   begin
     CoTaskMemFree(Result);
     raise Exception.Create('Could not convert string to PIDL');
   end;
end;

function PIDLToPath(const PIDL: PItemIDList): string;
var
  Path: array[0..Max_Path] of Char;
begin
  if ShGetPathFromIDList(PIDL, Path) then
   Result := Path
   else raise Exception.Create('Could not convert PIDL to string');
end;

procedure TfrmMain.FormCreate(Sender: TObject);
var
  s: string;
  PIDL: PItemIDList;
begin
  s := 'c:\uSERs\PUBlic\DeskTop';
  PIDL := PathToPIDL(s);
  s := PIDLToPath(PIDL);
  Memo1.Lines.Add(S);
end;
Zitat:
C:\Users\Public\Desktop
Viel Spass damit.

ps: Bearbeite das Uses, kann sein das da zuviel steht.
Gruß vom KodeZwerg

Geändert von KodeZwerg (19. Aug 2018 um 01:09 Uhr) Grund: uses hinzugefügt
  Mit Zitat antworten Zitat