Skip to content

Instantly share code, notes, and snippets.

@felipegtx
Created February 25, 2014 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felipegtx/9209926 to your computer and use it in GitHub Desktop.
Save felipegtx/9209926 to your computer and use it in GitHub Desktop.
Contador de bytes do Desafio 2
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