C# Program To Count File Extensions and Group It Using Linq
C# Program To Count File Extensions and Group It Using Linq
This C# Program Counts File Extensions and Group it using LINQ. Here a service reads
filesgenerated in a folder every hour and returns a string array containing the file names and
showes the count of files grouped by the file extension.
Here is source code of the C# Program to Count File Extensions and Group it using
LINQ. The C# program is successfully compiled and executed with Microsoft Visual
Studio. The program output is also shown below.
/*
1.
2.
3.
*/
4.
using System;
5.
using System.Collections.Generic;
6.
using System.Linq;
7.
using System.Text;
8.
using System.IO;
9.
namespace ConsoleApplication9
10.
11.
class Program
12.
13.
14.
{
string[] arr = { "aaa.txt", "bbb.TXT", "xyz.abc.pdf",
15.
16.
Path.GetExtension(file).TrimStart('.').ToLower())
.GroupBy(x => x,(ext, extCnt) =>new
17.
18.
19.
Extension
= ext,
Count =
20.
extCnt.Count()
});
21.
22.
foreach (var v in egrp)
23.
24.
",v.Count, v.Extension);
Console.ReadLine();
25.
26.
27.
28.