I do not know the feasibility of doing in lambda or Linq my expression

Asked

Viewed 37 times

0

I have these two lists:

List<string> dirZipDireto = ConfigurationManager.AppSettings["Dir_Zip_Direto"].Split(';').ToList();
List<string> arquivos = Directory.GetFiles(caminhoCommiter, "*", SearchOption.AllDirectories).ToList();

To minimize lines of code and give more beauty and consistency to the code, I think I can improve this and avoid some foreach. What I want:

I’d like to upload the list arquivos with files, except those that exist in the directory list dirZipDireto. Hence the code referring to arquivos can be minimized and in a single expression?

1 answer

2


How about?

var arquivosFiltrados = (from arquivo in arquivos
                         where !(from dirEvitar in dirZipDireto
                                 where arquivo.Contains(dirEvitar)
                                 select dirEvitar).Any()
                         select arquivo).ToList();
  • Jonathan, just one question. If I want to add one more list of files to the file filesFilted, in that same Bible, how do I do? I tried some shapes here and couldn’t add.

  • 1

    I solved with a Union the comment above.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.