Calculate average file size for a folder with C#
If you need to have an estimation of the average file size of a folder containing couple of files ? Easy with C#
class Program { static void Main(string[] args) { string[] dirfiles = Directory.GetFiles("c:\\software\\"); 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(); } }
![](https://i0.wp.com/samtech365.com/wp-content/uploads/2015/01/visual-studio-2013-logo1.png?fit=469%2C469&ssl=1)
If you need to have an estimation of the average file size of a folder containing couple of files ? Easy with C#
class Program { static void Main(string[] args) { string[] dirfiles = Directory.GetFiles("c:\\software\\"); 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(); } }