Environment.GetLogicalDrives Environment.GetLogicalDrives Environment.GetLogicalDrives Environment.GetLogicalDrives Method

Definition

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

public:
 static cli::array <System::String ^> ^ GetLogicalDrives();
public static string[] GetLogicalDrives ();
static member GetLogicalDrives : unit -> string[]
Public Shared Function GetLogicalDrives () As String()

Returns

String[]

An array of strings 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

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 namespace System;
int main()
{
   Console::WriteLine();
   array<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
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
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:\
'

Security

EnvironmentPermission
for full access to the resource protected by this permission. Associated enumeration: Unrestricted

Applies to