Export (0) Print
Expand All

Environment.GetLogicalDrives Method

Returns an array of string containing the names of the logical drives on the current computer.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

public static string[] GetLogicalDrives ()
public static String[] GetLogicalDrives ()
public static function GetLogicalDrives () : String[]

Return Value

An array of string where each element contains the name of a logical drive. For example, if the computer's hard drive is the first logical drive, the first element returned is "C:\".

Exception typeCondition

IOException

An I/O error occurs.

SecurityException

The caller does not have the required permissions.

// 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:\
*/

// Sample for the Environment.GetLogicalDrives method
import System.*;

class Sample
{
    public static void main(String[] args)
    {
        Console.WriteLine();
        String drives[] = Environment.GetLogicalDrives();
        Console.WriteLine("GetLogicalDrives: {0}", String.Join(", ", drives));
    } //main
} //Sample

/*
This example produces the following results:

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

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft