更新:2007 年 11 月
返回指定驱动器的 DriveInfo 对象。
' Usage
Dim value As System.IO.DriveInfo = My.Computer.FileSystem.GetDriveInfo(drive)
' Declaration
Public Function GetDriveInfo( _
   ByVal drive As String _
) As System.IO.DriveInfo
参数
- drive
 String。要检查的驱动器。必选。
返回值
异常
以下情况可能会导致异常:
- 路径由于以下原因之一而无效:它是零长度字符串;它仅包含空白;它包含无效字符;或者它是一个设备路径(以 \\.\ 开头)(ArgumentException)。 
- 路径无效,因为它是 Nothing (ArgumentNullException)。 
- 路径超过了系统定义的最大长度 (PathTooLongException)。 
- 路径中的文件名或文件夹名包含冒号 (:),或格式无效 (NotSupportedException)。 
- 用户缺少查看该路径所必需的权限 (SecurityException)。 
备注
DriveInfo 类可将驱动器建模,并提供用于查询驱动器信息的方法和属性。使用 DriveInfo 来确定哪些驱动器可用,以及这些驱动器的类型。也可以查询属性,以确定驱动器上的容量和可用空闲空间。
任务
下表列出了涉及 My.Computer.FileSystem.GetDriveInfo 方法的任务的示例。
| 要执行的操作 | 请参见 | 
|---|---|
| 确定驱动器的卷标 | |
| 确定驱动器的类型 | |
| 确定驱动器的总空间 | |
| 确定驱动器的物理空闲空间 | |
| 确定驱动器的根文件夹 | 
示例
此示例获取 C 驱动器的 DriveInfo 对象,并使用它来显示有关该驱动器的信息。
Dim getInfo As System.IO.DriveInfo
getInfo = My.Computer.FileSystem.GetDriveInfo("C:\")
MsgBox("The drive's type is " & getInfo.DriveType)
MsgBox("The drive has " & getInfo.TotalFreeSpace & " bytes free.")
有关不同驱动器类型的信息,请参见 DriveType。
要求
命名空间:Microsoft.VisualBasic.MyServices
类:FileSystemProxy(提供对 FileSystem 的访问)
**程序集:**Visual Basic 运行库(位于 Microsoft.VisualBasic.dll 中)
按项目类型列出的可用性
| 项目类型 | 可用 | 
|---|---|
| Windows 应用程序 | 是 | 
| 类库 | 是 | 
| 控制台应用程序 | 是 | 
| Windows 控件库 | 是 | 
| Web 控件库 | 是 | 
| Windows 服务 | 是 | 
| 网站 | 是 | 
权限
以下权限可能是必需的:
| 权限 | 说明 | 
|---|---|
| 控制访问文件和文件夹的能力。关联的枚举:Unrestricted。 |