alyncibi
alyncibi

Reputation: 13

View a subfolder in the same window as its parent?

I have a parent folder and it contains subfolders and other files ( text files, images, executables .. ) all laying together in the same path (actually, it's the path to their parent folder).

SendKeys.SendWait("sub");
SendKeys.SendWait("{ENTER}");

The two lines above perform the action I need; which is opening the folder called 'sub' in the same window of its parent folder view without opening a new one.(The picture shows the situation I would like to avoid, let's say I would like to find the best way to perform an equivalent action of "selecting" a sub folder and then pressing ENTER to open it in the same window without launching a separate and a new one)

enter image description here

Aany suggestions ? I read about default verbs in ShellExecuteA() but that doesn't seem to work for me;my code was

using System.Runtime.InteropServices;

namespace testFaza
{
    class Program
    {
        [DllImport("shell32.dll")]
        static extern int ShellExecuteA(int hwnd, string lpOperation, string lpFile, string lpParameters, string lpDirectory, int nShowCmd);

        static void Main(string[] args)
        {

            string path = @"sub\";
            ShellExecuteA(0, null, path, null, null, 1);
        }
    }
}

When I released, then when it executes, the output result is something like the first picture :

enter image description here

EDIT :

string path = @"sub\";
dynamic ws = Microsoft.VisualBasic.Interaction.CreateObject("WScript.Shell");       
ws.Run("explorer.exe /select, " + (char)34 + path + (char)34);

then a SendKey to hit {ENTER}, this is the best solution I came through till now.

Upvotes: 1

Views: 243

Answers (1)

Jeremy Thompson
Jeremy Thompson

Reputation: 65544

Explorer.exe supports a command line argument of /SELECT which will select files/folders, eg the sub folder:

string sPath = "c:\bin\release\sub";

//Start a Window and reliably select a subfolder
Process.Start("explorer.exe", " /select," & sPath);

//Open the folder
SendKeys.SendWait("{ENTER}");

Upvotes: 1

Related Questions