4
I am making an application whose purpose is to search and open a subdirectory inside a folder that is on a server. But what I can do so far is just search and open the folders that are at the root...
My code is like this:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string filepath = string.Format("C:\\TESTE\\{0}", textBox1.Text, SearchOption.AllDirectories);
System.Diagnostics.Process prc = new System.Diagnostics.Process();
prc.StartInfo.FileName = filepath;
prc.Start();
}
}
}
I know I have to use a recursive function to go through all the folders but I am not able to fit the function in what I want: the user inserts in the textbox the folder to search, press the search button and open and if there opens with the explorer that folder:
public void GetSubDirectories()
{
string root = @"C:\teste";
string[] subdirectoryEntries = Directory.GetDirectories(root);
foreach (string subdirectory in subdirectoryEntries)
LoadSubDirs(subdirectory);
}
private void LoadSubDirs(string dir)
{
Console.WriteLine(dir);
string[] subdirectoryEntries = Directory.GetDirectories(dir);
foreach (string subdirectory in subdirectoryEntries)
{
LoadSubDirs(subdirectory);
}
}
Someone wants to explain why -1?
– Omni
Yeah, I’ve seen it a lot, the folks negative the issue and want the guy to use psionic powers to understand the subjectivity of the gecko ass. I suppose it’s because you don’t answer the part of fitting the method and then open with the Explorer.
– Intruso