this code works fine but my problem is that i need to read the files that contains ESSD and if this file contains a name in certain line, add it to my listbox1, and if it doesnt contain the name in that line, dont add it to the listbox1.
Thanks.
private void button1_Click(object sender, EventArgs e)
{
DialogResult result = this.openFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
string[] Nomarchivo = this.openFileDialog1.FileNames;
string NomDirec = Path.GetDirectoryName(Nomarchivo[0]);
for (int a = 0; a <= Nomarchivo.Length - 1; a++)
{
string NomDirGral = Nomarchivo[a].Remove(Nomarchivo[a].Length - 7, 7);
string NomGral = NomDirGral.Replace(NomDirec, " ");
NomGral = NomGral.Remove(0, 2);
foreach (string f in Directory.GetFiles(NomDirec, NomGral + "*"))
this.listBox1.Items.Add(f);
foreach (string h in Directory.GetFiles(NomDirec, "resume*"))
this.listBox1.Items.Add(h);
foreach (string t in Directory.GetFiles(NomDirec, "ESSD1*"))
this.listBox1.Items.Add(t);
}
string[] list1 = new string[listBox1.Items.Count];
for (int b = 0; b <= listBox1.Items.Count - 1; b++)
{
list1[b] = listBox1.Items[b].ToString();
}
string[] list2 = list1.Distinct().ToArray();
foreach (string g in list2)
this.listBox2.Items.Add(g);
Class1 arr1 = new Class1();
arr1.array(listBox2);
}
else { Close(); }
}
.NET 4 offers a nice function called File.ReadLines(fileName)
With this function, your above code can be modified as: