Environment.GetLogicalDrives Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
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
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 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
open System
let drives = Environment.GetLogicalDrives()
String.concat ", " drives
|> printfn "\nGetLogicalDrives: %s"
// 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
End Class
'
'This example produces the following results:
'
'GetLogicalDrives: A:\, C:\, D:\
'
Applies to
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기