vts123
vts123

Reputation: 1776

Open Folder and Select multiple files

In C# I want to open explorer and in this explorer window must be selected some files. I do this like that:

        string fPath = newShabonFilePath;

        string arg = @"/select, ";

        int cnt = filePathes.Count;
        foreach (string s in filePathes)
        {
            if(cnt == 1)
                arg = arg + s;
            else
            {
                arg = arg + s + ",";
            }
            cnt--;
        }

        System.Diagnostics.Process.Start("explorer.exe", arg);

But only the last file of "arg" is selected. How to make that all files of arg would be selected, when explorer window is opened..? I think its possible to do that, becouse I have seen many Windows app programs, which have this trick. In example, when I import pictures from my DSLR camera to the pc, finally apears windows explorer and all the new imported images are selected.

Maybe there is some option, to make all files to be selected from specified folder..?

Upvotes: 4

Views: 4055

Answers (2)

Rob Fonseca-Ensor
Rob Fonseca-Ensor

Reputation: 15621

Could you launch each file in the loop?

foreach (string s in filePaths)
    System.Diagnostics.Process.Start("explorer.exe", "/select, "+s);

P.S. string.Join is a greatly underused feature of .NET

Upvotes: 0

Espo
Espo

Reputation: 41919

explorer.exe /select only takes 1 argument. From KB 314853:

/select, Opens a window view with the specified folder, file, or program selected.

Upvotes: 2

Related Questions