programming-examples/c-sharp/Linq/C# Sharp to Calculate Size of File using LINQ.cs

18 lines
681 B
C#
Raw Normal View History

2019-11-15 12:59:38 +01:00
using System;
using System.Linq;
using System.IO;
class LinqExercise16
{
static void Main(string[] args)
{
string[] dirfiles = Directory.GetFiles("/home/w3r/abcd/");
// there are three files in the directory abcd are :
// abcd.txt, simple_file.txt and xyz.txt
Console.Write("\nLINQ : Calculate the Size of File : ");
Console.Write("\n------------------------------------\n");
var avgFsize = dirfiles.Select(file =>new FileInfo(file).Length).Average();
avgFsize = Math.Round(avgFsize / 10, 1);
Console.WriteLine("The Average file size is {0} MB",avgFsize);
Console.ReadLine();
}
}