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;