Program to calculate the File size in specified folder using LINQ

Prabhukiran345
Posted by Prabhukiran345 under LINQ category on | Points: 40 | Views : 715

static void Main(string[] args)
{
string[] dirfiles = Directory.GetFiles("c:\\myFoldername\\");
var avg = dirfiles.Select(file =>
new FileInfo(file).Length).Average();
avg = Math.Round(avg/1000000, 1);
Console.WriteLine("The Average file size is {0} MB",
avg);
Console.ReadLine();
}


Output Will BE:
The Average file size is 1(Your File Size) MB

Comments or Responses

Login to post response