简体   繁体   English

打开文件夹并选择多个文件

[英]Open Folder and Select multiple files

In C# I want to open explorer and in this explorer window must be selected some files. 在C#中,我想打开资源管理器,并且必须在此资源管理器窗口中选择一些文件。 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. 但是仅选择了“ arg”的最后一个文件。 How to make that all files of arg would be selected, when explorer window is opened..? 打开资源管理器窗口时,如何使所有arg文件都被选中? I think its possible to do that, becouse I have seen many Windows app programs, which have this trick. 我认为这样做是有可能的,因为我已经看过许多具有此技巧的Windows应用程序。 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. 例如,当我将照片从DSLR相机导入到PC时,最终将终止Windows资源管理器并选择所有新导入的图像。

Maybe there is some option, to make all files to be selected from specified folder..? 也许有一些选择,可以从指定的文件夹中选择所有文件。

explorer.exe /select only takes 1 argument. explorer.exe /select仅接受1个参数。 From KB 314853 : KB 314853

/select, Opens a window view with the specified folder, file, or program selected. / select,打开一个带有选定文件夹,文件或程序的窗口视图。

Could you launch each file in the loop? 您可以在循环中启动每个文件吗?

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

PS string.Join is a greatly underused feature of .NET PS 字符串。Join是.NET的一个未被充分利用的功能

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM