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