G'day all,

The program i'm currently working on has a search feature, I want to be able to search a Folder and any Sub-Folders contained within that structure. I'm really confused at the moment as to how i'm going to keep going deeper into a directory and still manage to search other folders also, I was doing some pretty funky stuff with the GetDirectories method - mostly because i'm new to C#.. :S. I appreciate any help you can provide.

Here is my current code:

try
            {
                // Loop through each ticked drive
                foreach (string chkDrive in CkBox_Drives.CheckedItems)
                {
                    // Search for directories in current directory 
                    for (string[] directories = Directory.GetDirectories(chkDrive); directories.Count().Equals(0); directories.Count().DoesNotEqual(0))
                    {
                        foreach (string files in Directory.GetFiles(chkDrive, "*.exe"))
                        {
                            CkBox_Found.Items.Add(files);
                        }
                    }
                }
            }
            catch (System.Exception excpt)
            {
                MessageBox.Show(excpt.Message);
            }

>how i'm going to keep going deeper into a directory and still manage to search other folders.
Use,

System.IO.Directory.GetDirectories("path", "pattern", System.IO.SearchOption.AllDirectories);

>how i'm going to keep going deeper into a directory and still manage to search other folders.
Use,

System.IO.Directory.GetDirectories("path", "pattern", System.IO.SearchOption.AllDirectories);

Thanks for the quick reply!, and it helped! :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.