问题
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