7

My favorite IDE Wing IDE has a command for showing the active file in Explorer. This means that when you launch the command, it opens an explorer window on the folder that the file is in, and then selects the file.

The problem is, that if the window is already open, it fails to select the file. It activates the window, but the file doesn't get selected. That's annoying. I want the file to always be selected

I spoke to one of the developers and he said that they're using 'explorer /select,%s' % filename to show the file, and that the above annoyance might be a quirk of that command.

Does anyone have an idea how to avoid this behavior?

(The solution needs to work in Windows 2000, XP, 2003 Server, Vista, and Windows 7.)

Ram Rachum
  • 84,019
  • 84
  • 236
  • 374
  • A related question exists, one of the answers points to API calls; It might help a bit: http://stackoverflow.com/questions/3887364/opening-an-explorer-window-with-designated-file-selected – Larry Dec 06 '12 at 13:02
  • On which OS do you see the problem? Do you see the same problem when running 'explorer /select,...' from a cmd.exe? – Werner Henze Dec 07 '12 at 14:49
  • 1. It happens on XP. 2. I tested, and yes, the same problem happens when I run it directly from a terminal. – Ram Rachum Dec 08 '12 at 18:40
  • Does the problem go away if you modify the Wing IDE shortcut so that it runs in compatibility mode (e.g. XP SP3 mode)? – Darth Continent Dec 11 '12 at 19:01
  • I am already running on Windows XP. The compatibility options are 95, 98&Me, NT4SP5, and 2000. – Ram Rachum Dec 12 '12 at 14:15

2 Answers2

2

As per https://support.microsoft.com/en-us/kb/152457, which states "switches can be combined", what about:

explorer /n,/select,c:\path\to\file.ext

/n should force a new window.

Shannon Matthews
  • 9,649
  • 7
  • 44
  • 75
El Zorko
  • 3,349
  • 2
  • 26
  • 34
  • I don't want to force a new window. I want to use an existing one if it exists. – Ram Rachum Dec 13 '12 at 13:02
  • Ah, I see. I can't see a programmatic solution to your problem in that case, since there are no command line switches to achieve what you want, and if shell coding isn't an option, that's about it. There might be configuration tweaks you could do on each machine, but that'd be a question for superuser.com not stackoverflow since this is a programming Q&A site. – El Zorko Dec 13 '12 at 13:28
0

I dont know if one exists, but if you create utility which would be implement such solution(C++) it would work as you expected:

void OpenFileInExplorer(LPCTSTR filename)
{
    ITEMIDLIST *pidl = ILCreateFromPath(filename);
    if(pidl) 
    {
        SHOpenFolderAndSelectItems(pidl,0,0,0);
        ILFree(pidl);
    }
}
Anton Semenov
  • 6,227
  • 5
  • 41
  • 69
  • Thanks for the code, but I can't program in C++ so this doesn't help me. – Ram Rachum Dec 13 '12 at 11:14
  • I do not see C++ in the given code. BTW, don't forget to call `CoInitializeEx` before calling SHOpenFolderAndSelectItems! – Werner Henze May 23 '13 at 12:13
  • @Werner Henze: that's right, call `CoInitializeEx` first is obligatory and... that code was actually writen in C++, :-) I know only C++, C# and ABAP. And the code above can be recognized only like C++ for me – Anton Semenov May 23 '13 at 13:32