DirectoryInfo Example

In the spirit of our DriveInfo example, which was a little slip of a thing, here’s a DriveInfo example.

using System;
using System.Collections.Generic;
using System.IO;

class DirectoryInfoExample
    static void Main(string[] args)
        string dir = @"C:\";
        Console.WriteLine("Listing directories underneath {0}", dir);
        DirectoryInfo diList = new DirectoryInfo(dir);
        foreach (DirectoryInfo di in diList.GetDirectories())
            Console.WriteLine("{0}", di.FullName);
        Console.WriteLine("Listing files in {0}", dir);

        foreach (FileInfo fi in diList.GetFiles())
            Console.WriteLine("File name:  {0}\nCreated:  {1},\nLength:   {2} bytes",
                 fi.Name, fi.CreationTime, fi.Length);

John Lockwood is a software developer who apparently doesn't work hard enough at the job he gets paid to work hard at, he has to also hang around here and write these tutorials. And by the way, THANK YOU to all those who've forked the tutorials on Github. Pull requests written around new articles would be kinda cool! (hint hint).

Posted in Miscellaneous

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>