# Sunday, July 01, 2007
« Avoiding End to End Testing | Main | Recursively Deleting a Directory - Take ... »
I needed to remove about 60 subdirectories named "_thumbs" from my pictures directory.  Of course manually doing this through Explorer wasn't something I was up for.  I tried to do it through the command line, but RD doesn't support multiple directories as inputs.  I wanted to do this:

dir /AD /B /S *_thumbs* | rd /s

but that didn't work, so I had to write my own RD command that is capable of piping input through it - which was still faster than doing it through Explorer.

dir /AD /B /S *_thumbs* | consoleapplication1

using System;
using System.IO;
using log4net;

namespace ConsoleApplication1
{
    class Program
    {
        private static readonly ILog Logger = LogManager.GetLogger(typeof(Program));

        static void Main(string[] args)
        {
            string input;
            do
            {
                input = Console.ReadLine();

                if (input != null)
                    DeleteDir(input);

            } while (input != null);
        }

        private static void DeleteDir(string input)
        {
            if (Directory.Exists(input))
            {
                Logger.InfoFormat("Deleting directory {0}", input);
                Directory.Delete(input, true);
            }
            else
                Logger.WarnFormat("Directory {0} does not exist", input);
        }
    }
}


Monday, July 02, 2007 3:21:33 AM (GMT Standard Time, UTC+00:00)
What *I* would have done was bring up a Windows "Find" at the parent, and brought back all folders named "_Thumbs". Then I would have done a <Ctrl>+A followed by s <Shift>+<Del>.

=)
RyanB
Monday, July 02, 2007 7:58:38 PM (GMT Standard Time, UTC+00:00)
That's a good idea. I think I just got stuck on the fact that the command line would be the place to do this. Also, I've learned to ignore the Windows search function over the years because it has sucked.
Sneal
Comments are closed.