How to open windows explorer when I click a button? How to open windows explorer when I click a button? windows windows

How to open windows explorer when I click a button?


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


Building on what Mason Wheeler said: you can also pass in a directory as an argument, to get the window to open to a non-default location:

uses  ShellAPI;...  ShellExecute(Application.Handle,    nil,    'explorer.exe',    PChar('c:\'), //wherever you want the window to open to    nil,    SW_NORMAL     //see other possibilities by ctrl+clicking on SW_NORMAL    );


Try this:

ShellExecute(Application.Handle, nil, 'explorer.exe', nil, nil, SW_NORMAL);

You'll need to add ShellAPI to your uses clause.