C# program to get computer drive names of a given directory

Directory.GetLogicalDrives()

Syntax:

string[] Directory.GetLogicalDrives();

Program:

using System;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            string[] drives;

            drives = Directory.GetLogicalDrives();

            Console.WriteLine("Computer Drives:");
            for (int i = 0; i < drives.Length; i++)
            {
                Console.WriteLine("\t" + drives[i]);
            }

        }
    }
}

Output:

Computer Drives:
        C:\
        D:\
        E:\
        F:\

Leave a Comment

error: Alert: Content is protected!!