AleksandarKostadinov

Folder Size

Feb 12th, 2017
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.54 KB | None | 0 0
  1. namespace _05.FolderSize
  2. {
  3.     using System.IO;
  4.     using System;
  5.     using System.Linq;
  6.  
  7.     class Program
  8.     {
  9.         static void Main()
  10.         {
  11.             var files = Directory.GetFiles("TestFolder");
  12.             long sum = 0;
  13.  
  14.             foreach (var file in files)
  15.             {
  16.                 var fileInfo = new FileInfo(file);
  17.                 sum += fileInfo.Length;
  18.             }
  19.  
  20.             var sumInMB = (sum / 1024.0) / 1024.0;
  21.  
  22.             File.WriteAllText("result.txt", sumInMB.ToString());
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment