Einzelnen Beitrag anzeigen

Benutzerbild von toms
toms
(CodeLib-Manager)

Registriert seit: 10. Jun 2002
4.648 Beiträge
 
Delphi XE Professional
 
#4

Re: Wie kann man "zuletzt verwendete Dokumente" au

  Alt 29. Dez 2003, 19:43
Zitat:
Ich möchte alle LNK-Dateien im Verzeichnis "zuletzt verwendete Dokumente" auslesen.
Delphi-Quellcode:
uses
  ActiveX, ShlObj;

function GetRecentFilesPath: string;
var
  shellMalloc: IMalloc;
  ppidl: PItemIdList;
  PerDir: string;
begin
  ppidl := nil;
  try
    if SHGetMalloc(shellMalloc) = NOERROR then
    begin
      SHGetSpecialFolderLocation(0, CSIDL_RECENT, ppidl);
      SetLength(Result, MAX_PATH);
      if not SHGetPathFromIDList(ppidl, PChar(Result)) then
        raise Exception.Create('SHGetPathFromIDList failed : invalid pidl');
      SetLength(Result, lStrLen(PChar(Result)));
    end;
  finally
    if ppidl <> nil then
      shellMalloc.free(ppidl);
  end;
end;

procedure FileList(sPath, sExt: string ; List: TStrings);
var
  dir: TSearchRec;
  ret: Integer;
begin
  ret := FindFirst(sPath + '\' + sExt, faAnyFile, dir);
  if ret <> NO_ERROR then
    Exit;
  try
    while ret = NO_ERROR do
    begin
      if (dir.Name <> '.') and (dir.Name <> '..') then
        List.Add(dir.name);
      ret := FindNext(Dir);
    end;
  finally
    FindClose(dir);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  FileList(GetRecentFilesPath, '*.lnk', ListBox1.Items);
end;
Thomas
  Mit Zitat antworten Zitat