bool ItemIsExcluded(Item item) { if (ExcludedFileTypes != null) { return(item.FileName.ToLower().EndsWithAny(ExcludedFileTypes.Select(t => t.ToLower()).ToArray())); } return(false); }
private bool FindAndAddFoundDirectories(ref List <MyTuple> resultSearchList, string path, string searchPattern) { var result = false; if (!Directory.Exists(path)) { return(false); } if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(searchPattern)) { return(result); // Empty list } if (!Directory.Exists(path)) { return(result); // Empty list } var excludedStringsList = ExcludedFileTypes.Split(';').ToList(); List <string> listOfAllDirectories = new List <string>(); int counter = 0; try { // Get all directories except excluded ones listOfAllDirectories = Directory.GetDirectories(path, searchPattern, SearchOption.AllDirectories).ToList(); listOfAllDirectories.ExcludeItemsInList(excludedStringsList); if (listOfAllDirectories != null && listOfAllDirectories.Count > 0) { foreach (var dir in listOfAllDirectories) // loop directories { // Hämta filer i subbibliotek //var _TempListOfFilesInSearchedDirectory = Directory.GetFiles(dir).ToList(); var _TempListOfFilesInSearchedDirectory = new List <string>(); try { _TempListOfFilesInSearchedDirectory = Directory.EnumerateFiles(dir).ToList(); } catch (Exception e) { continue; } resultSearchList.Add(new MyTuple(dir.GetFileNameFromPath(), dir, "", true, "", "")); foreach (var fileName in _TempListOfFilesInSearchedDirectory) { counter++; bool containsExcludedString = excludedStringsList.Exists(w => fileName.ToUpper().Contains(w.ToUpper())); if (!containsExcludedString) { FileInfo fi = new FileInfo(fileName); resultSearchList.Add( new MyTuple( fileName.GetFileNameFromPath(), fileName.ToString(), "", false, fileName.GetSuffixFromPath(), fi.Length.ToString())); result = true; } } } } } catch (UnauthorizedAccessException uaec) { MessageBox.Show(uaec.Message); return(false); } catch (Exception e) { MessageBox.Show("counter: " + counter.ToString() + e.Message); return(false); } return(result); }