Program to calculate the File size in specified folder using LINQ

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

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",

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

Comments or Responses

Login to post response