У меня есть IEnumerable <DirectoryInfo>, который я хочу отфильтровать, используя массив регулярных выражений, чтобы найти возможные совпадения. Я пытаюсь присоединиться к моим каталогам и строкам регулярных выражений, используя linq, но не может показаться, что это правильно. Вот что я пытаюсь сделать ...Найти сопоставленные каталоги, используя список регулярных выражений
string[] regexStrings = ... // some regex match code here.
// get all of the directories below some root that match my initial criteria.
var directories = from d in root.GetDirectories("*", SearchOption.AllDirectories)
where (d.Attributes & (FileAttributes.System | FileAttributes.Hidden)) == 0
&& (d.GetDirectories().Where(dd => (dd.Attributes & (FileAttributes.System | FileAttributes.Hidden)) == 0).Count() > 0// has directories
|| d.GetFiles().Where(ff => (ff.Attributes & (FileAttributes.Hidden | FileAttributes.System)) == 0).Count() > 0) // has files)
select d;
// filter the list of all directories based on the strings in the regex array
var filteredDirs = from d in directories
join s in regexStrings on Regex.IsMatch(d.FullName, s) // compiler doesn't like this line
select d;
... любые предложения о том, как я могу заставить это работать?
А, хороший звонок на Any(). Я все время забываю об этом! –
Doh! - Я тоже забыл об этом (Any & All). –