private int ProcessDirectory(DirectoryInfo directoryInfo, int fileCount, ref int rowCount, StringBuilder sb, int theCount)
        {
            if (directoryInfo.FullName.Contains("_svn"))
            {
                return(fileCount);
            }

            string query = search.Text;

            DirectoryInfo[] subDirectories = directoryInfo.GetDirectories();
            foreach (DirectoryInfo subDirectory in subDirectories)
            {
                //Recursion going on here...
                fileCount += ProcessDirectory(subDirectory, fileCount, ref rowCount, sb, theCount);
            }

            FileInfo[] fileInfos = directoryInfo.GetFiles();
            foreach (FileInfo file in fileInfos)
            {
                if ((file.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
                {
                    continue;
                }
                if (file.FullName.Contains(("_svn")))
                {
                    continue;
                }

                fileCount++;
                using (StreamReader reader = file.OpenText())
                {
                    string row = reader.ReadLine();
                    while (row != null)
                    {
                        rowCount++;

                        Regex           ex    = new Regex(query, RegexOptions.None);
                        MatchCollection found = ex.Matches(row);


                        if (found.Count > 0)
                        {
                            sb.Append("<br/><b>");
                            //sb.Append("<a href=\"corpus");//Plain text

                            //corpus\\forums\jan Mato\(C) Stulkan sem starir a hafid.txt
                            sb.Append("<a href=\"DisplayText.aspx?file=");
                            string[] splitOn = new [] { "corpus" };
                            sb.Append(file.FullName.Split(splitOn, StringSplitOptions.RemoveEmptyEntries)[1]);
                            sb.Append("\">");
                            sb.Append(CorpusUtils.ExtractTitle(file.Name));
                            sb.Append("</a> ");
                            sb.Append(" by ");
                            sb.Append(CorpusUtils.ExtractAuthor(file.DirectoryName));
                            sb.Append("</b><br/>");

                            foreach (var foo in found)
                            {
                                theCount++;
                                sb.Append("<b>");
                                sb.Append(foo.ToString());
                                sb.Append("</b>: ");
                            }
                            sb.Append(row);
                            sb.Append("<br/>");

                            if (theCount > 100)
                            {
                                DisplayOutput(fileCount, rowCount, sb);
                                return(fileCount);
                            }
                        }
                        row = reader.ReadLine();
                    }
                }
            }
            return(fileCount);
        }
        private int ProcessDirectory(DirectoryInfo directoryInfo, int fileCount, ref int rowCount, StringBuilder sb, int theCount)
        {
            if (directoryInfo.FullName.Contains("_svn") || directoryInfo.FullName.Contains(".svn"))
            {
                return(fileCount);
            }
            //string query = search.Text;

            DirectoryInfo[] subDirectories = directoryInfo.GetDirectories();
            foreach (DirectoryInfo subDirectory in subDirectories)
            {
                //Recursion going on here...
                fileCount += ProcessDirectory(subDirectory, fileCount, ref rowCount, sb, theCount);
            }

            FileInfo[] fileInfos = directoryInfo.GetFiles();
            foreach (FileInfo file in fileInfos)
            {
                if ((file.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
                {
                    continue;
                }
                if (file.FullName.Contains("_svn") || file.FullName.Contains(".svn"))
                {
                    continue;
                }

                fileCount++;
                using (StreamReader reader = file.OpenText())
                {
                    string row = reader.ReadToEnd();

                    if (row == null)
                    {
                        continue;
                    }

                    sb.Append("<tr><td>");
                    sb.Append("<a href=\"DisplayText.aspx?file=");
                    string[] splitOn = new[] { "corpus" };
                    sb.Append(file.FullName.Split(splitOn, StringSplitOptions.RemoveEmptyEntries)[1]);
                    sb.Append("\">");
                    sb.Append(CorpusUtils.ExtractTitle(file.Name));
                    sb.Append("</a></td><td>");
                    sb.Append(CorpusUtils.ExtractAuthor(file.DirectoryName));
                    sb.Append("</td>");

                    //metrics

                    Metrics metrics = MetricsCalculator.Calculate(row);
                    sb.Append("<td>");
                    sb.Append(string.Format("{0:0.0}", metrics.ComplexNounPhrasePercent));
                    sb.Append("</td><td>");
                    sb.Append(string.Format("{0:0.0}", metrics.CoordinatingPercent));
                    sb.Append("</td><td>");
                    sb.Append(string.Format("{0:0.0}", metrics.FunctionWordPercent));
                    sb.Append("</td><td>");
                    sb.Append(string.Format("{0:0.0}", metrics.ProperModiferPercent));
                    sb.Append("</td><td>");
                    sb.Append(string.Format("{0:0.0}", metrics.WordsPerSentence));
                    sb.Append("</td><td>");

                    double composite =
                        (metrics.WordsPerSentence / 9.5
                         +
                         metrics.ProperModiferPercent / .5
                         +
                         metrics.FunctionWordPercent / 2.5
                         +
                         metrics.CoordinatingPercent / 0.3
                         +
                         metrics.ComplexNounPhrasePercent / 0.3) / 5;

                    sb.Append(string.Format("{0:0.0}", composite));
                    sb.Append("</td>");
                    sb.Append("</tr>");
                }
            }

            return(fileCount);
        }