How to open windows explorer when I click a button?

Tobassum Munir picture Tobassum Munir · Aug 11, 2009 · Viewed 20.1k times · Source

I have a form in a Delphi project. There is a button on the form. When the user clicks the button, I want it to open Windows Explorer.

What code will I need to achieve this?

Answer

zz1433 picture zz1433 · Aug 11, 2009

Well in case you need to select some particular file in explorer I have the following function which I use

procedure SelectFileInExplorer(const Fn: string);
begin
  ShellExecute(Application.Handle, 'open', 'explorer.exe',
    PChar('/select,"' + Fn+'"'), nil, SW_NORMAL);
end;

and you can call it :

SelectFileInExplorer('C:\Windows\notepad.exe');

EDIT: As mentioned ShellAPI must be added to your uses list