procedure OpenExplorerAndSelectFile(FileName: TFileName);
begin
shellexecute(0, 'open', pchar('Explorer'),
pchar('/e,/select, "' + FileName + '"'), nil, SW_SHOWNA);
end;
// Variante 2
// (Stammt nicht von mir)
// Scrollt die Datei auch noch ins Sichtfeld
uses Winapi.ShellApi, Winapi.ShlObj;
const
OFASI_EDIT = $0001;
OFASI_OPENDESKTOP = $0002;
{$IFDEF UNICODE}
function ILCreateFromPath(pszPath: PChar): PItemIDList stdcall;
external shell32 name 'ILCreateFromPathW';
{$ELSE}
function ILCreateFromPath(pszPath: PChar): PItemIDList stdcall;
external shell32 name 'ILCreateFromPathA';
{$ENDIF}
procedure ILFree(pidl: PItemIDList)stdcall; external shell32;
function SHOpenFolderAndSelectItems(pidlFolder: PItemIDList; cidl: Cardinal;
apidl: pointer; dwFlags: DWORD): HRESULT; stdcall; external shell32;
function OpenFolderAndSelectFile(const FileName: string): boolean;
var
IIDL: PItemIDList;
begin
result := false;
IIDL := ILCreateFromPath(PChar(FileName));
if IIDL <> nil then
try
result := SHOpenFolderAndSelectItems(IIDL, 0, nil, 0) = S_OK;
finally
ILFree(IIDL);
end;
end;
// Beispielaufruf
procedure TForm1.Button1Click(Sender: TObject);
begin
OpenFolderAndSelectFile('D:\Bilder\Zylinder.jpg');
end;