public void GetFilesWithExtensionWithInvalidPath() { string path = @"C:\masm32\bin\gffg\dd"; string extension = "exe"; FilesSearcher filesSearcher = new FilesSearcher(path, extension); Assert.Throws <ArgumentException>(() => filesSearcher.GetFilesWithExtension()); }
static async Task Main(string[] args) { Console.Write("Directory or press Enter to use assembly folder:"); var directory = Console.ReadLine(); if (directory == string.Empty) { directory = Environment.CurrentDirectory; } var validator = new DirectoryPathValidator(); var error = validator.Validate(directory); if (!string.IsNullOrEmpty(error)) { LogErrorAndDie(error); } Console.WriteLine("Lookin up for files. Wait a sec..."); var searcher = new FilesSearcher(); string[] filePaths = Array.Empty <string>(); try { filePaths = await searcher.GetFilePaths(new[] { directory }, FileType.LAS).ConfigureAwait(false); } catch (Exception ex) { Console.WriteLine("Found errors"); LogErrorAndDie(ex.Message); } Console.WriteLine($"Found {filePaths.Length} files"); if (filePaths.Length == 0) { Console.WriteLine("Have nothing to do, halting"); Environment.Exit(0); } Console.WriteLine("Parsing files. Wait a sec..."); LASFilesParser parser = new LASFilesParser(Environment.ProcessorCount); IEnumerable <LASFileData> structuredData = Enumerable.Empty <LASFileData>(); try { structuredData = await parser.Parse(filePaths); } catch (Exception ex) { LogErrorAndDie(ex.Message); } Console.WriteLine("Building index. Wait a sec..."); var indexer = new Indexer(); Func <LASFileData, IEnumerable <string[]> > fieldsSelector = x => x.Sections.SelectMany(s => s.Lines.Select(l => new[] { l.Description, l.Mnemonic })); var d1 = structuredData.SelectMany(x => fieldsSelector(x).SelectMany(d => d.Select(z => (x.FilePath, z)))); try { indexer.Build(d1); } catch (Exception ex) { LogErrorAndDie(ex.Message); } Console.WriteLine("Index built successfully."); Console.WriteLine("Just type field names and hit enter, and I will show results."); Console.WriteLine("For example, type 'LTYP' or 'LOG TYPE'"); while (true) { Console.WriteLine("---------------"); var term = Console.ReadLine(); if (IsExit(term)) { Environment.Exit(0); } var res = indexer.Query(term); foreach (var item in res) { Console.WriteLine($"{item.field} - {item.filePath}"); } } }
private void FindMethod() { _isWorking = true; //если выбран вариант поиска файлов без поиска текста внутри файлов //(chbSearchWithText.Enabled = false, searchTextInFiles = false), все остается по-старому if (!searchTextInFiles) { if (this.fileMasks.Length > 0) { UtilSubSys.FilesSearcher searcher = new FilesSearcher(); this.result = new FilesSearcher.SearchResults(); this.result = searcher.GetFiles(directoryToFindFrom, this.fileMasks, true); foreach (FilesSearcher.FoundObjectInfo curObjInfo in bgFinder.result.foundObjectsList) { foundFilesSize += curObjInfo.Size; } if (FilesHaveBeenFound != null) { FilesHaveBeenFound(); } } else { UtilSubSys.FilesSearcher searcher = new FilesSearcher(); this.result = new FilesSearcher.SearchResults(); this.result = searcher.GetFiles(directoryToFindFrom, true); foreach (FilesSearcher.FoundObjectInfo curObjInfo in bgFinder.result.foundObjectsList) { foundFilesSize += curObjInfo.Size; } if (FilesHaveBeenFound != null) { FilesHaveBeenFound(); } } } //если же выбран вариант поиска файлов с поиском текста внутри файлов, //предыдущий вариант поиска должен быть соответствующим образом изменен else { if (this.fileMasks.Length > 0) { UtilSubSys.FilesSearcher searcher = new FilesSearcher(); //если выбрана опция поиска текста только вначале файлов, //необходимо присвоить соответствующее значение переменной searchAtFilesBegining //объекту класса FilesSearcher searcher.searchAtFilesBegining = searchTextAtFilesBegining; this.result = new FilesSearcher.SearchResults(); this.result = searcher.GetFiles(directoryToFindFrom, this.fileMasks, this.searchingText, true); //подсчет занимаемого найденными файлами дискового пространства foreach (FilesSearcher.FoundObjectInfo curObjInfo in bgFinder.result.foundObjectsList) { foundFilesSize += curObjInfo.Size; } if (FilesHaveBeenFound != null) { FilesHaveBeenFound(); } } else { UtilSubSys.FilesSearcher searcher = new FilesSearcher(); //если выбрана опция поиска текста только вначале файлов, //необходимо присвоить соответствующее значение переменной searchAtFilesBegining //объекту класса FilesSearcher searcher.searchAtFilesBegining = searchTextAtFilesBegining; string[] fileMask = { "*.*" }; this.result = new FilesSearcher.SearchResults(); this.result = searcher.GetFiles(directoryToFindFrom, fileMask, this.searchingText, true); //подсчет занимаемого найденными файлами дискового пространства foreach (FilesSearcher.FoundObjectInfo curObjInfo in bgFinder.result.foundObjectsList) { foundFilesSize += curObjInfo.Size; } if (FilesHaveBeenFound != null) { FilesHaveBeenFound(); } } } _isWorking = false; }