June 2008 Entries

count lines with linq

so i needed to count the lines of a bunch of different filetypes in a folder. i decided to try using linq for this. here's what i came up with. basically a single linq statement =P you can tune the regex to taste. i just said (i think, i'm not a regex wizard) something that isn't a newline (.+) and the line terminators i'm using (\r\n).   using System; using System.Collections; using System.IO; using System.Linq; using System.Text.RegularExpressions; namespace LineCounter {     class LineCounter     {         static void Main(string[] args)         {             // dir to search             string d = @"c:\pathtocode";             // regex match for newlines             string lf = @".+\r\n";                         // get the...

directory list with a stack instead of recursion

Stack q = new Stack(); q.Push(argument); while (q.Count > 0) {     string d = q.Pop().ToString();     Console.WriteLine(d);     foreach (string sd in Directory.GetDirectories(d))         q.Push(sd); }