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 =Pyou 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...

posted @ Wednesday, June 11, 2008 2:07 PM | Feedback (1)

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);}

posted @ Tuesday, June 10, 2008 6:41 PM | Feedback (0)