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

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

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Reply