How to Get the List of All Drives installed in the System using C# ?

Your 2020 Plan. Learn 20 minutes a day for 20 days. Online courses from €9.99.

If you need to get the list of all drives installed on your system using C# , you can use the DriveInfo class which provides the static method GetDrives.

How to Get the List of All Drives installed in the System using C# ?

Below is a code snippet that iterates through all the drives and provides the necessary information about them.

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.IO;
namespace GinktageConsoleApp
{
    internal class Program
    {
        private static void Main(string[] args)
        {
           var DrivesInPC = DriveInfo.GetDrives();
            foreach(var drive in DrivesInPC)
            {
                Console.WriteLine(drive.Name);
            }
           Console.ReadLine();
        }     
    }
    
}

1

Leave a Reply

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