This documentation is archived and is not being maintained.

Environment.GetLogicalDrives Method

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

[Visual Basic]
Public Shared Function GetLogicalDrives() As String()
[C#]
public static string[] GetLogicalDrives();
[C++]
public: static String* GetLogicalDrives()  __gc[];
[JScript]
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:\".

Exceptions

Exception Type Condition
IOException An I/O error occurs.
SecurityException The caller does not have the required permissions.

Example

[Visual Basic] 
' Sample for the Environment.GetLogicalDrives method
Imports System

Class Sample
   Public Shared Sub Main()
      Console.WriteLine()
      Dim drives As [String]() = Environment.GetLogicalDrives()
      Console.WriteLine("GetLogicalDrives: {0}", [String].Join(", ", drives))
   End Sub 'Main
End Class 'Sample
'
'This example produces the following results:
'
'GetLogicalDrives: A:\, C:\, D:\
'

[C#] 
// 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:\
*/

[C++] 
// Sample for the Environment::GetLogicalDrives method
#using <mscorlib.dll>

using namespace System;

int main() {
   Console::WriteLine();
   String*  drives[] = Environment::GetLogicalDrives();
   Console::WriteLine(S"GetLogicalDrives: {0}", String::Join(S", ", drives));
}
/*
This example produces the following results:

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

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

Environment Class | Environment Members | System Namespace

Show: