For example i have this function that search for files:
public void Search(string strExtension,
DirectoryInfo di,
List<FileSystemInfo> pResult)
{
try
{
foreach (FileInfo fi in di.GetFiles())
{
if (InvokeRequired)
{
BeginInvoke(new Action(() => label2.Text = fi.Name));
}
if (fi.Name == "MessageLog.xsl")
{
foreach (FileInfo fii in di.GetFiles())
{
if (fii.Extension == strExtension)
pResult.Add(fii);
}
if (InvokeRequired)
{
BeginInvoke(new Action(() => label4.Text = pResult.Count.ToString() + Environment.NewLine));
}
}
}
foreach (DirectoryInfo diChild in di.GetDirectories())
Search(strExtension, diChild, pResult);
}
catch (Exception e)
{
}
}
When the search is over im using this small class :
public class MyItem
{
public FileSystemInfo fsi { get; set; }
public override string ToString()
{
return this.fsi.Name;
}
}
And show in the backGroundWorker completed event the files names:
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
for (int i = 0; i < this.fsi.Count; i++)
{
this.listBox1.Items.Add(new MyItem() { fsi = fsi[i] });
}
}
The result in the listBox is for example like this:
danny125645.xml
yaron576567.xml
This are file names without the directories.
Is there anyway to parse the file name so it will be without the numbers ? For example:
danny.xml
yaron.xml