コード例 #1
0
        public void SearchInFiles()
        {
            DirectoryTreeWalker directoryTreeWalker = new DirectoryTreeWalker();
            directoryTreeWalker.SearchSubDirectories = true;
            directoryTreeWalker.WalkTheTree(SearchRootPath);

            //ok now the tree has been walked. Get the list of all the text files and then determine the presence of the strings
            string fileContent = string.Empty;

            foreach (string file in directoryTreeWalker.Files)
            {
                fileContent = ReadTextFile(file);

                KMPEngine kmpEngine = new KMPEngine(fileContent, SearchPattern);

                List<int> occurences = kmpEngine.Find(false, true);

                if (occurences.Count == 0)
                    continue;

                if (occurences[0] != -1)
                {
                    _fileNamesWithContentPresent.Add(file);
                }
            }
        }
コード例 #2
0
        public void SearchInFiles(bool searchSubDirectories, FileMetaAttributeFilter fileFilter)
        {
            DirectoryTreeWalker directoryTreeWalker = new DirectoryTreeWalker();
            directoryTreeWalker.SearchSubDirectories = searchSubDirectories;
            directoryTreeWalker.WalkTheTree(SearchRootPath);

            //ok now the tree has been walked. Get the list of all the text files and then determine the presence of the strings
            string fileContent = string.Empty;

            foreach (string file in directoryTreeWalker.Files)
            {
                if (!Utilities.IsTextFile(file))
                    continue;

                FileMetaAttributes fileAttributes = Utilities.GetFileMetaAttributes(file);

                if (null != fileFilter && !Utilities.EvaluateMetaAttributeFilters(fileAttributes, fileFilter))
                    continue;

                fileContent = Utilities.ReadTextFromFiles(file);

                KMPEngine kmpEngine = new KMPEngine(fileContent, SearchPattern);

                List<int> occurences = kmpEngine.Find(true, true);

                if (occurences.Count == 0)
                    continue;

                if (occurences[0] != -1)
                {

                    _fileNamesWithContentPresent.Add(file);

                    _fileNameToOccurencePositionsMap.Add(file, occurences);
                }
            }
        }