10

Using the following

explorer.exe /select, "c:\path\to\file.txt"

I can open Windows Explorer and select the file. In Delphi I do this to select "Parm" file:

ShellExecute(Application.MainForm.Handle, 'OPEN', PChar('explorer.exe'), PChar('/select,"' + Parm + '"'), nil, SW_NORMAL);

And it works. My problem is this: if I select a different file in the recently opened Explorer (clicking in a different file) and then call the above code the "Parm" file is not selected again. Interestingly, there are some programs that select the file again. For instance, ITunes always selects the desired file.

Does anyone have a clue of how to make Explorer always select the specified file?

Eduardo Mauro
  • 1,517
  • 1
  • 26
  • 38

1 Answers1

14

This is a known limitation of using the /select switch with explorer.exe, it will only select the specific file if the parent folder is not already open.

You'll have to use an API call like SHOpenFolderAndSelectItems in stead. This function also allows for multiselect.

Paul-Jan
  • 16,057
  • 58
  • 87
  • Perfect, thanks, i was trying to recall name of this function atm – Free Consulting Nov 27 '10 at 16:14
  • 1
    An excellent example of SHOpenFolderAndSelectItems can be found here: http://stackoverflow.com/questions/15300999/open-windows-explorer-directory-select-a-specific-file-in-delphi – Lars Mar 18 '14 at 09:11