Environment.GetLogicalDrives Method

Definition

Retrieves the names of the logical drives on this computer.

public static string[] GetLogicalDrives ();

Returns

String[]

An array of strings representing the logical drive names.

Exceptions

An I/O error occurs.

The caller does not have the required permissions.

Examples

The following example shows how to display the logical drives of the current computer using the GetLogicalDrives method.

// Sample for the Environment.GetLogicalDrives method
using System;

class Sample
{
    public static void Main()
    {
    Console.WriteLine();
    String[] drives = Environment.GetLogicalDrives();
    Console.WriteLine("GetLogicalDrives: {0}", String.Join(", ", drives));
    }
}
/*
This example produces the following results:

GetLogicalDrives: A:\, C:\, D:\
*/

Remarks

On Windows, GetLogicalDrives returns the names of all accessible drives on a particular machine, including any optical drives or removable media devices, in the form "<drive letter>:\" (for example, "C:\"). On Unix, it returns the paths of all filesystem mount points mounted on a particular machine (for example, "/home/user", "/media/usb").

Applies to

Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1