'Windows explorer.exe /select <filepath> doesn't work with new folders

I copy or rename a folder containing some files.

Then, in a command line window I type:

explorer /select,"<full-path-to-a-file-in-new-folder>"

The result is, the folder opens but the file isn't selected. Subsequent calls are fine, this happens only for newly created/renamed folders for the first time ever.

Is this a Windows bug? Is there a way around it?



Solution 1:[1]

I just ran into this same problem while trying to use the ShellExecuteEx() to run the Explorer.exe with the /select, to pick a file. Explorer doesn't reliably select the file the first time. Maybe it's a bug ... I found a few work arounds for it.

  • Set Explorer to execute as a separate process. This can be done in folder options and selecting "Launch each folder windows in a separate process".
  • Another workaround I found to work is creating a batch file to and launch Explorer from there with explorer.exe /select,"%~1" using the full file name as parameter into the batch file.
  • The last solution is what I ended up doing since I'm writing a program in C++. I used SHOpenFolderAndSelectItems() function.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 nosurprisespls