Friday, 12 May 2017

Directory & DirectoryInfo

Just like the file class is a static way to interact with files, the Directory class is a static way to interact with Directories, where as the DirectoryInfo class is an instance way to deal with directories.

using System;
using System.IO;

namespace DirectoryIoExample
{
    class Program
    {
        static void Main(string[] args)
        {
            DirectoryInfo di = new DirectoryInfo(@"c:\");
           
            foreach(var fi in  di.GetFiles())
                Console.WriteLine(fi.Name);
           
            foreach(var fi in Directory.GetFiles(@"c:\"))
                Console.WriteLine(fi);
        }
    }
}

Not exactly rocket surgery.