C# Program to Read the List of Available Disk Drives

You are currently viewing C# Program to Read the List of Available Disk Drives

C# program to read the list of available disk drives

//C# program to read the list of available disk drives.

using System.IO;
using System;

class Demo
{
    static void ReadDrives()
    {
        DriveInfo[] drvList = DriveInfo.GetDrives();

        foreach (DriveInfo drv in drvList)
        {
            Console.WriteLine("Drive Name: "+ drv.Name      );
            Console.WriteLine("\tDrive Type: "+ drv.DriveType );
            
            if (drv.IsReady == true)
            {
                long size=0;
                size = (drv.TotalSize) / (1024*1024*1024);
                Console.WriteLine("\tSize of drive in GB "+size +"\n");    
            }
        }
    }
    public static void Main()
    {
        ReadDrives();
    }
}
Drive Name: C:\
        Drive Type: Fixed
        Size of drive in GB 50

Drive Name: D:\
        Drive Type: Fixed
        Size of drive in GB 97

Drive Name: E:\
        Drive Type: Fixed
        Size of drive in GB 97

Drive Name: F:\
        Drive Type: CDRom
Drive Name: H:\
        Drive Type: Removable
Press any key to continue . . .

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply