1

I have two listboxes with files in them now I want to open Directory of selected file with button click.

            string rootdir = @"C:\Users\isaced1\Desktop\test";   //root directory of all projects
        string[] files = Directory.GetFiles(rootdir, "*.ini", SearchOption.AllDirectories);  //searches for specific .ini files in all directories whithin rood directory
        //cycles through all .ini files and adds it to lsitbox1 or listbox2
        foreach (string item in files)
        {
            string fileContents = File.ReadAllText(item); //reads all .ini files
            const string PATTERN = @"OTPM              = true"; //search pattern in .ini files
            Match match = Regex.Match(fileContents, PATTERN, RegexOptions.IgnoreCase); //matches pattern with content in .ini file

            if (match.Success)
            {
                listBox1.Items.Add(item); //if match is successfull places file in lisbox1
                listBox1.ForeColor = Color.Green;
            }
            else
            {
                listBox2.Items.Add(item); //if match is unsuccessfull places file in lisbox2
                listBox2.ForeColor = Color.Red;
            }
        }

I know how to open file with just Proccess.Start(filename), but how I can open directory?

Katonas
  • 39
  • 3
  • Check out this answer: https://stackoverflow.com/questions/1132422/open-a-folder-using-process-start. It's exactly what you want to do – crazy_crank Sep 26 '22 at 06:05
  • So you know that you open a file by passing the file path to `Process.Start`, but you can't think of any way that you might open a folder? Really? There's no obvious option that you're overlooking? – John Sep 26 '22 at 06:05
  • 1
    Does this answer your question? [Open a folder using Process.Start](https://stackoverflow.com/questions/1132422/open-a-folder-using-process-start) – MrCodingB Sep 26 '22 at 06:17

0 Answers0