Greetings, I’m trying to write a Linq query to run on a list of filenames which returns a list of files Grouped into 5MB chunks. So each group will contain a list of filenames whose total/summed MB is 5MB maximum.
I’m okay with Linq but this one I don’t know where to begin. Help
DirectoryInfo di = new DirectoryInfo (@"x:\logs");
List<string> FileList = di.GetFiles ("*.xml")
var Grouped = FileList =>
Yeah, you can do this with LINQ.
This algorithm is greedy. It just finds the first list it can shove the
FileInfointo without blowing past the upper bound of 5MB. It isn’t optimal in terms of minimizing the number of groups but you didn’t state that as a constraint. I think anOrderBy(f => f.Length)before the call toAggregatewould help but I don’t really have time to think deeply about that right now.