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
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