@Anshuman_Malik sorry, it was making my head hurt and didn’t get around to it. I thought there might be a fast way to use GroupBy(), however, I couldn’t wrap my head around it. So instead I took an easier approach just to basically loop over the files and group them by taking their sum, then remove those files from the initial array, and repeat.
psuedocode:
Assign files array from directory
Initialize List of files array to add each group to
While files.Count > 0
Initialize fileGroup
Initialize sizeSum
For each f In files array
If sizeSum + New FileInfo(f).Length <= sizeLimit
Assign sizeSum = sizeSum + New FileInfo(f).Length
Assign fileGroup = fileGroup.Concat({f})
Assign files = files.Where(Function(f) Not fileGroup.Contains(f) ).ToArray
Add to Collection //adds to fileGroups List
FileGroupsBySize.xaml (13.8 KB)
Here you go as an example. You can also turn this into a re-usable if you want by changing the List variable to an ‘out’ argument, and the directory, pattern, and sizeLimit to ‘in’ arguments.
I placed a Write Line to output the results of the fileGroups List, so you can see how it joined the files together. You can remove the Write Line, as it’s only temporary.
With the List (named fileGroups in this example), you can use in a ForEach loop to upload into a system, add as attachments, or zip or join pdf then upload… so, it’s up to you.
Regards.