Selecting file in Windows Explorers does not alway

2019-03-19 03:52发布

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?

1条回答
看我几分像从前
2楼-- · 2019-03-19 04:29

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.

查看更多
登录 后发表回答