Created
February 25, 2014 14:33
-
-
Save felipegtx/9209926 to your computer and use it in GitHub Desktop.
Contador de bytes do Desafio 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Linq; | |
namespace Desafio2 | |
{ | |
class Program | |
{ | |
private static string[] EXTENSIONS = new string[] { | |
".exe", ".log", ".pdb", ".js", ".html", ".htm", | |
".xhtml", ".xsl", ".xslt", ".hta", ".txt", ".css", ".dll", ".obj" | |
}; | |
private static bool ShouldCountLength(FileInfo fileInfo) | |
{ | |
return fileInfo != null | |
&& (from e in EXTENSIONS where e == fileInfo.Extension select true).FirstOrDefault(); | |
} | |
static void Main(string[] args) | |
{ | |
var directory = @"c:\TMP\tst"; | |
Console.WriteLine(string.Format("Total Size: '{0}' bytes", | |
Directory.EnumerateFiles(directory, "*.*", SearchOption.AllDirectories) | |
.Select(f => new FileInfo(f)) | |
.Where(ShouldCountLength) | |
.Select(fi => fi.Length) | |
.Sum() | |
)); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment