Search This Blog

Friday, February 21, 2014

Notepad++ command line wild card expander

Here is a C# command line expander for notepad++.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace Notepad___CommandLIneTool
    class Program
        static void Main(string[] args)
            string currentPath;
            string filePath;
            string fileName;

            //Get the current path
            currentPath = Directory.GetCurrentDirectory();

            //Loop through the arguments
            foreach (string arg in args)
                //Get file path and name
                filePath = Path.GetDirectoryName(arg);
                fileName = Path.GetFileName(arg);

                //Overly blank paths with current path
                if (filePath == string.Empty)
                    filePath = currentPath;

                //Detect wild card
                if (arg.IndexOf("*") != -1)
                    //Get a list of all files matching the file name in the path
                    DirectoryInfo di = new DirectoryInfo(filePath);
                    foreach (FileInfo fi in di.GetFiles(fileName))
                        //Open the file
                        OpenFile(filePath + "\\" + fi.Name);
                    //Open the file
                    OpenFile(filePath + "\\" + fileName);


        static void OpenFile(string fileName)
            //Setup notepad command
            ProcessStartInfo psi = new ProcessStartInfo();
            psi.FileName = "Notepad++.exe";
            psi.Arguments = fileName;
            psi.WorkingDirectory = @"C:\Program Files (x86)\Notepad++";

            //Execute the process

No comments:

Post a Comment