Selecting file in Windows Explorers does not always work

那年仲夏 提交于 2019-12-04 11:55:40

问题


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:


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.



来源:https://stackoverflow.com/questions/4291793/selecting-file-in-windows-explorers-does-not-always-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!