0

I can do this task in a normal form application but i am brand new to working with WPF applications.

I want to enter a directory path in a TextBox, then click a Button which validates and recursively searches that path, and displays all the files in a ListBox.

I have already looked at this article but i don't understand it fully because again, i'm very new to this.

Any help would be appreciated.

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
user2189007
  • 1
  • 1
  • 1
  • What don't you understand from the link you linked ? The example there is 5 lines if we exclude the try catch. – coolmine Mar 20 '13 at 02:10
  • 2
    FYI, searching directory recursively doesn't have anything to do with WPF. This is base C#. – joce Mar 20 '13 at 02:29

2 Answers2

5

Try this.

DirectoryInfo dir = new DirectoryInfo("your path");
dir.GetFiles("*.*", SearchOption.AllDirectories);
Dilshod
  • 3,189
  • 3
  • 36
  • 67
  • 5
    Use `EnumerateFiles` for efficiency: http://stackoverflow.com/questions/5669617/what-is-the-difference-between-directory-enumeratefiles-vs-directory-getfiles – Bennor McCarthy Mar 20 '13 at 02:15
1

Or this;

void DirSearch(string sDir) 
{
    try 
    {
       foreach (string d in Directory.GetDirectories(sDir)) 
       {
        foreach (string f in Directory.GetFiles(d, txtFile.Text)) 
        {
           lstFilesFound.Items.Add(f);
        }
        DirSearch(d);
       }
    }
    catch (System.Exception excpt) 
    {
        Console.WriteLine(excpt.Message);
    }
}
CryptoJones
  • 734
  • 3
  • 11
  • 33
  • so i place this in but what code do i put in the search button event handler? – user2189007 Mar 20 '13 at 03:20
  • 1
    +1. @user2189007 - you asked question about making recursive search. If you really needed something else (which seem to be the case based on this comment) - please ask separate question with exact task you have problem with. – Alexei Levenkov Mar 20 '13 at 03:33