LINQ: Select where object does not contain items from list

后端 未结 4 1256
被撕碎了的回忆
被撕碎了的回忆 2020-12-02 11:51

I\'m struggling with LINQ syntax here...thought I\'d toss it out here. I cant find exactly what I\'m looking for anywhere else.

OK, say I\'ve got this:



        
4条回答
  •  广开言路
    2020-12-02 12:20

    Try this simple LINQ:

    //For a file list/array
    var files = Directory.GetFiles(folderPath, "*.*", SearchOption.AllDirectories);
    
    //simply use Where ! x.Contains
    var notContain = files.Where(x => ! x.Contains(@"\$RECYCLE.BIN\")).ToList();
    
    //Or use Except()
    var containing = files.Where(x => x.Contains(@"\$RECYCLE.BIN\")).ToList();
        notContain = files.Except(containing).ToList();
    

提交回复
热议问题