Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I display Explorer with a file selected?

What's the API call to display an Explorer window with a specified file selected? Exactly as happens when you click the "Find Target..." button in the Properties dialog of a .lnk shortcut? I know there is function (or an interface method) for that, but I forgot the name, and cannot find it again.

Note that I'm aware of explorer /select,<pathname> command line and not interested in using it instead of API call.

like image 957
Premature Optimization Avatar asked Jun 02 '11 22:06

Premature Optimization


People also ask

How do I change File Explorer view?

Press Windows Key + E to open File Explorer. Click the View option in the menu bar at the top of the window. In the drop-down menu, select Extra large icons, Large icons, Medium Icons, Small icons, List, Details, Tiles, or Content to change to the view you want to see.


1 Answers

This function opens explorer, and selects the specified file:

uses ShellAPI, ...;

procedure TForm1.ShowFile(const aFileName:String);
begin
  ShellExecute(Handle, 'OPEN', PChar('explorer.exe'), PChar('/select, "' + aFileName + '"'), nil, SW_NORMAL)
end;

procedure TForm1.ShowFolder(const aPath:String);
begin
  ShellExecute(Handle, 'OPEN', PChar('explorer.exe'), PChar('/root, "' + aPath + '"'), nil, SW_NORMAL) 
end;

Or is this the "commandline" that you didn't want to use?

like image 94
Wouter van Nifterick Avatar answered Sep 21 '22 20:09

Wouter van Nifterick