Reputation: 20464
It's possibly to add a field in this LINQ instruction to exclude files containing a word when sorting the list?
Dim Files As List(Of IO.FileInfo) = _
Get_Files(Directory, True, ValidExtensions) _
.OrderBy(Function(x) x.Name.ToLower.Contains("word")) _
.ThenBy(Function(x) x.Extension).ToList
What I want is to add a field to exclude from the creation of the list files which contains a word, I know I can exclude them in the function who get the files (Get_Files) but I want to know if it's possibly to do it using LINQ.
Upvotes: 0
Views: 41
Reputation: 22794
Dim Files As List(Of IO.FileInfo) = _
Get_Files(Directory, True, ValidExtensions) _
.Where(Function(x) Not x.Name.ToLower.Contains("your word")) _
.OrderBy(Function(x) x.Name.ToLower.Contains("word")) _
.ThenBy(Function(x) x.Extension).ToList
Upvotes: 1
Reputation: 63522
Add a Where
clause
.Where(Function(x) x.Name.ToLower.Contains("skip") = False)
.OrderBy(Function(x) x.Name.ToLower.Contains("word")) _
.ThenBy(Function(x) x.Extension).ToList
Upvotes: 4