Return to Snippet

Revision: 59833
at October 4, 2012 02:38 by ed_trench


Initial Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace CentreFolderDeduper
{
    class Program
    {
        static void Main(string[] args)
        {
            String[] centreFolders = Directory.GetDirectories(args[0]);
            List<String> centres = new List<String>();

            foreach(var centreFolder in centreFolders)
            {
                if (centreFolder.IndexOf('-') != -1)
                {
                    centres.Add(centreFolder.Left(centreFolder.IndexOf('-')));
                }
            }
                        
            var duplicateFolders = from f in centres
                                   group f by f.ToString() into g
                                   where g.Count() > 1
                                   select new { CentreFolderName = g.Key, CentreFolderNameCount = g.Count() };

            Console.WriteLine(duplicateFolders.Count());
            ObjectDumper.Write(duplicateFolders);
            Console.ReadKey();
        }
    }
}

Initial URL

                                

Initial Description
simple LINQ and a Left extension method

Initial Title
LINQ and Extension method (simple)

Initial Tags

                                

Initial Language
C#