HpToolsLauncher.Helper.WalkDirectoryTree C# (CSharp) Method

WalkDirectoryTree() static private method

static private WalkDirectoryTree ( System root, List &results ) : void
root System
results List
return void
        static void WalkDirectoryTree(System.IO.DirectoryInfo root, ref List<string> results)
        {
            System.IO.FileInfo[] files = null;
            System.IO.DirectoryInfo[] subDirs = null;

            // First, process all the files directly under this folder
            try
            {

                files = root.GetFiles("*" + STFileExtention);
                files = files.Union(root.GetFiles("*" + QTPFileExtention)).ToArray();
                files = files.Union(root.GetFiles("*" + LoadRunnerFileExtention)).ToArray();
            }
            catch (Exception e)
            {
                // This code just writes out the message and continues to recurse.
                // You may decide to do something different here. For example, you
                // can try to elevate your privileges and access the file again.
                //log.Add(e.Message);
            }

            if (files != null)
            {
                foreach (System.IO.FileInfo fi in files)
                {
                    if (fi.Extension == LoadRunnerFileExtention)
                        results.Add(fi.FullName);
                    else
                        results.Add(fi.Directory.FullName);

                    // In this example, we only access the existing FileInfo object. If we
                    // want to open, delete or modify the file, then
                    // a try-catch block is required here to handle the case
                    // where the file has been deleted since the call to TraverseTree().
                }

                // Now find all the subdirectories under this directory.
                subDirs = root.GetDirectories();

                foreach (System.IO.DirectoryInfo dirInfo in subDirs)
                {
                    // Recursive call for each subdirectory.
                    WalkDirectoryTree(dirInfo, ref results);
                }
            }
        }