I have a folder with files (the files in this folder can variate in number):
XXX_1.jpg
XXX_2.jpg
ZZZ_1.jpg
ZZZ_2.jpg
BBB_1.jpg
YYY_1.jpg
I want to populate a listView that has two columns: Name & Count.
In this example, the listView should look like this:
XXX 2
ZZZ 2
BBB 1
YYY 1
How would I go about constructing a LINQ query to separate name & count from the items in the folder and then populate the listView with the name of the file + how many times its in the directory?
Here’s how I started:
IEnumerable<string[]> groups = originalFiles
.GroupBy(policyName => policyName.Split('_')[0])
.Select(g => g.ToArray());
foreach (var group in groups)
{
//add group name + count in listView
}
I need to add Count() somewhere there but I’m not really sure.
Try this
Good Luck !!