Environment.GetLogicalDrives 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
检索此计算机上的逻辑驱动器的名称。
public:
static cli::array <System::String ^> ^ GetLogicalDrives();
public static string[] GetLogicalDrives();
static member GetLogicalDrives : unit -> string[]
Public Shared Function GetLogicalDrives () As String()
返回
String[]
表示逻辑驱动器名称的字符串数组。
例外
出现 I/O 错误。
调用方没有所需的权限。
示例
以下示例演示如何使用 GetLogicalDrives 该方法显示当前计算机的逻辑驱动器。
// 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:\
'
注解
在Windows,GetLogicalDrives以“<drive letter>:\”的形式返回特定计算机上所有可访问驱动器的名称,包括任何光学驱动器或可移动媒体设备的名称(例如“C:\”)。 在 Unix 上,它将返回在特定计算机上装载的所有文件系统装入点的路径(例如“/home/user”、“/media/usb”)。