c# - linq where any intersect contains -


soooo... writing tool task collect xmls on servers based on parameters.

here's code have far:

private list<string> getlistxmls(string strpath, list<string> colctnames) {     string regexexpr = "\\\\\\\\" + strstager + "\\\\appli\\\\" + strenvir + "\\\\[a-za-z]{3}\\\\bin\\\\";      if(colctnames == null)     {             list<string> xmlcolct = directory.getfiles(strpath, "*.*", searchoption.alldirectories)                                                     .where(x => regex.ismatch(x, regexexpr, regexoptions.ignorecase) &&                                                                 x.tolower().contains("msgtrait") &&                                                                 x.endswith(".xml"))                                                     .tolist();              return xmlcolct;     }     else     {         list<string> xmlcolct = directory.getfiles(strpath, "*.*", searchoption.alldirectories)                                                     .where(x => regex.ismatch(x, regexexpr, regexoptions.ignorecase) &&                                                                 x.tolower().contains("msgtrait") &&                                                                 x.endswith(".xml"))                                                     .tolist();          list<string> finallist = new list<string>();         foreach (string strfich in xmlcolct)         {             if (colctnames.any(item => strfich.tolower().contains(item.tolower())))             {                 finallist.add(strfich);             }         }          return finallist;         // include kind of linq method want instead of stripping down list...     }   } 

basically need files on server match abn_msgtrait.xml. need if user seeking orl, uqm or blablabla, method get needed list instead of stripping down results need. bear in mind list xmlcolct list of paths may contain orl name in this: orl_msgtrait.xml.

so question is: there way merge foreach i'm doing in linq request avoid having retrieve xmls , strip unwanted ones?

list<string> xmlcolct = directory.getfiles(strpath, "*.*", searchoption.alldirectories)      .where(x => regex.ismatch(x, regexexpr, regexoptions.ignorecase) &&         x.tolower().contains("msgtrait") &&         x.endswith(".xml") &&         colctnames.any(item => x.tolower().contains(item.tolower())))     .tolist();  

but if using regex can add that:

  1. it ends ".xml"
  2. contains "msgtrait" @ name area
  3. and any part string.join in order form pattern optional values of colctnames

Comments