Showing file in Windows Explorer
Asked Answered
S

2

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.)

Swadeshi answered 4/12, 2012 at 11:48 Comment(5)
A related question exists, one of the answers points to API calls; It might help a bit: #3887864Masha
On which OS do you see the problem? Do you see the same problem when running 'explorer /select,...' from a cmd.exe?Jolinejoliotcurie
1. It happens on XP. 2. I tested, and yes, the same problem happens when I run it directly from a terminal.Swadeshi
Does the problem go away if you modify the Wing IDE shortcut so that it runs in compatibility mode (e.g. XP SP3 mode)?Expiratory
I am already running on Windows XP. The compatibility options are 95, 98&Me, NT4SP5, and 2000.Swadeshi
A
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.

Artwork answered 13/12, 2012 at 12:44 Comment(2)
I don't want to force a new window. I want to use an existing one if it exists.Swadeshi
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.Artwork
P
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);
    }
}
Proliferous answered 13/12, 2012 at 9:7 Comment(3)
Thanks for the code, but I can't program in C++ so this doesn't help me.Swadeshi
I do not see C++ in the given code. BTW, don't forget to call CoInitializeEx before calling SHOpenFolderAndSelectItems!Jolinejoliotcurie
@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 meProliferous

© 2022 - 2024 — McMap. All rights reserved.