I have created a find a file class and I have added the method below that calls itself (recursively). It goes through all sub folders from a given starting folder and adds a specified file to a collection of the class with the path. Now this should be pretty fimple but it doesn't work if the starting point is C:/ unless i add the messagebox when the file is found. If I comment out the messagebox call the application just hangs.
Because it works with the messagebox I know that the stack limit is not reached. Any input or ideas would be great.
Thanks,
Einar
public void SearchForFile (System.String sPath)
{
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(sPath);
System.IO.FileSystemInfo[] dirs = di.GetDirectories();
if (System.IO.File.Exists(sPath + "\\" + this.FileName))
{
this.FileCollection.Add(sPath + "\\" + this.FileName);
System.Windows.Forms.MessageBox.Show("found a file");
}
foreach (System.IO.DirectoryInfo diNext in dirs)
{
this.SearchForFile(diNext.FullName.ToString());
}
}
Semper ubi sub ubi.