GetLogicalDrives in C#


To get all the disk drives on a system, use the GetLogicalDrives() method in C# −

Environment.GetLogicalDrives()

Use it with Join method to get the comma-separated list of logical drives −

string.Join(",", Environment.GetLogicalDrives())

Example

 Live Demo

using System;
using System.IO;
namespace Demo {
   class Program {
      static void Main(string[] args) {
         Console.WriteLine(string.Join(",", Environment.GetLogicalDrives()));
      }
   }
}

Output

/,/etc/resolv.conf,/etc/hostname,/etc/hosts,/run/secrets,/home/cg/root

Updated on: 22-Jun-2020

155 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements