DuckMaestro
DuckMaestro

Reputation: 15875

How to open multiple files in a single action in Visual Studio

I often use the "Command Window" in Visual Studio to quickly open a file by name, for instance by typing open main.c.

However what doesn't seem to work is open *.xyz, the intent being to open any files in the solution with some extension xyz.

Is there a quick and easy way from the Command Window to open multiple files at once based on a pattern?

Upvotes: 1

Views: 2912

Answers (3)

user8880165
user8880165

Reputation: 1

you can use find command to do that:

$find . -name "*.xyz" -exec open {} \;

Upvotes: -1

user1529413
user1529413

Reputation: 464

Here is a solution using Visual Commander which is a VS add-on. It uses file paths from the clipboard. I tend to drop to a command line use a dir /s/b *.?? or another more complicated solution using powershell to generate these file paths.

using EnvDTE;
using EnvDTE80;
using System;
using System.Windows.Forms;
using System.IO;

public class C : VisualCommanderExt.ICommand
{
    public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package) 
    {
        if(Clipboard.ContainsText(TextDataFormat.Text))
        {
            string[] files = Clipboard.GetText(TextDataFormat.Text).Replace("\r","").Split(new string[] {"\n"}, StringSplitOptions.RemoveEmptyEntries);
            foreach(string f in files)
            {
                try 
                {
                    FileInfo fileInfo = new FileInfo(f);
                    if(fileInfo.Exists)
                    {
                        DTE.ItemOperations.OpenFile(f, EnvDTE.Constants.vsViewKindPrimary);
                    }
                }
                catch{ }
            }
        }
    }
}

Upvotes: 1

Hans
Hans

Reputation: 2320

I couldn't get the command window to work. Use a text editor or a script to make a list of files like this:

"full path 1" "full path 2"

Ctrl+o and paste the string into the open file dialog.

Upvotes: 3

Related Questions