SoFunction
Updated on 2025-03-06

C# Method to obtain directory information and attributes using Directoryinfo class

This article describes the method of using Directoryinfo class to obtain directory information and properties in C#. Share it for your reference. The details are as follows:

using System;
using ;
class MainClass {
  static void Main(string[] args) {
    FileInfo file = new FileInfo("c:\\");
    // Display directory information.
    DirectoryInfo dir = ;
    ("Checking directory: " + );
    ("In directory: " + );
    ("Directory exists: ");
    (());
    if () {
      ("Directory created: ");
      (());
      ("Directory last updated: ");
      (());
      ("Directory last accessed: ");
      (());
      ("Directory attribute list: ");
      (());
      ("Directory contains: " +
        ().() + " files");
    }
    ();
  }
}

I hope this article will be helpful to everyone's C# programming.