Articles → CSHARP → Driveinfo Class In C#

Driveinfo Class In C#






Purpose





Example




using System;
using System.IO;

namespace DriverInfo {
  class Program {
    static void Main(string[] args) {
      DriveInfo[] allDrives = DriveInfo.GetDrives();

      foreach(DriveInfo d in allDrives) {
        Console.WriteLine("Drive {0}", d.Name);
        Console.WriteLine("  Drive type: {0}", d.DriveType);
        if (d.IsReady == true) {
          Console.WriteLine("  Volume label: {0}", d.VolumeLabel);
          Console.WriteLine("  File system: {0}", d.DriveFormat);
          Console.WriteLine(
            "  Available space to current user:{0, 15} bytes",
            d.AvailableFreeSpace);

          Console.WriteLine(
            "  Total available space:          {0, 15} bytes",
            d.TotalFreeSpace);

          Console.WriteLine(
            "  Total size of drive:            {0, 15} bytes ",
            d.TotalSize);
        }

        Console.ReadLine();
      }
    }
  }
}



Output


Picture showing the output of DriveInfo class in C#
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Tuesday, March 21, 2017

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250