May 20, 2022

Samir Daoudi's Technical Blog

SharePoint, Office 365, C#, .Net, SQL Server News, Tips, Ebooks, Events, Webinars ….etc

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 var avg = dirfiles verage(); riteLine("The Average file size is {0} MB", avg);

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();
 }
}

Leave a comment

You may have missed

Show Buttons
Hide Buttons

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

%d bloggers like this: