To get the system drives in C# and VB.NET you can use the following snippet.

Sample C#

public static DriveInfo[] GetDrives(bool runningDrivesOnly)
{
	return runningDrivesOnly ? Enumerable.Cast<DriveInfo>(DriveInfo.GetDrives()).Where(x => x.IsReady).ToArray() : DriveInfo.GetDrives();
}

Sample VB.NET

Public Shared Function GetDrives(runningDrivesOnly As Boolean) As DriveInfo()
	Return If(runningDrivesOnly, Enumerable.Cast(Of DriveInfo)(DriveInfo.GetDrives()).Where(Function(x) x.IsReady).ToArray(), DriveInfo.GetDrives())
End Function

One thought on “How to get the system drives in C# and VB.NET”

Leave a Reply