.NET Framework 类库 |
DriveInfo 类 |
请参见 示例 成员 |
注意:此类在 .NET Framework 2.0 版中是新增的。
提供对有关驱动器的信息的访问。
命名空间:System.IO
程序集:mscorlib(在 mscorlib.dll 中)
语法
Visual Basic(声明) |
---|
< SerializableAttribute > _ < ComVisibleAttribute (True)> _ Public NotInheritable Class DriveInfo Implements ISerializable |
Visual Basic(用法) |
---|
Dim instance As DriveInfo |
C# |
---|
[ SerializableAttribute ] [ ComVisibleAttribute (true)] public sealed class DriveInfo : ISerializable |
C++ |
---|
[ SerializableAttribute ] [ ComVisibleAttribute (true)] public ref class DriveInfo sealed : ISerializable |
J# |
---|
/** @attribute SerializableAttribute () */ /** @attribute ComVisibleAttribute (true) */ public final class DriveInfo implements ISerializable |
JScript |
---|
SerializableAttribute ComVisibleAttribute (true) public final class DriveInfo implements ISerializable |
备注
此类对驱动器进行建模,并提供方法和属性以查询驱动器信息。使用 DriveInfo 可以确定可用的驱动器以及这些驱动器的类型。还可以通过查询来确定驱动器的容量和可用空闲空间。
示例
下面的代码示例演示如何使用 DriveInfo 类显示有关当前系统中所有驱动器的信息。
Visual Basic | 复制代码 |
---|---|
Imports System Imports System.IO Class Test Public Shared Sub Main() Dim allDrives() As DriveInfo = DriveInfo.GetDrives() Dim d As DriveInfo For Each d In allDrives Console.WriteLine("Drive {0}", d.Name) Console.WriteLine(" File type: {0}", d.DriveType) If d.IsReady = True Then Console.WriteLine(" Volume label: {0}", d.VolumeLabel) Console.WriteLine(" File system: {0}", d.DriveFormat) Console.WriteLine( _ " Available space to current user:{0, 15} bytes", _ d.AvailableFreeSpace) Console.WriteLine( _ " Total available space: {0, 15} bytes", _ d.TotalFreeSpace) Console.WriteLine( _ " Total size of drive: {0, 15} bytes ", _ d.TotalSize) End If Next End Sub End Class 'This code produces output similar to the following: ' 'Drive A:/ ' File type: Removable 'Drive C:/ ' File type: Fixed ' Volume label: ' File system: FAT32 ' Available space to current user: 4770430976 bytes ' Total available space: 4770430976 bytes ' Total size of drive: 10731683840 bytes 'Drive D:/ ' File type: Fixed ' Volume label: ' File system: NTFS ' Available space to current user: 15114977280 bytes ' Total available space: 15114977280 bytes ' Total size of drive: 25958948864 bytes 'Drive E:/ ' File type: CDRom ' 'The actual output of this code will vary based on machine and the permissions 'granted to the user executing it. |
C# | 复制代码 |
---|---|
using System; using System.IO; class Test { public static void Main() { DriveInfo[] allDrives = DriveInfo.GetDrives(); foreach (DriveInfo d in allDrives) { Console.WriteLine("Drive {0}", d.Name); Console.WriteLine(" File type: {0}", d.DriveType); if (d.IsReady == true) { Console.WriteLine(" Volume label: {0}", d.VolumeLabel); Console.WriteLine(" File system: {0}", d.DriveFormat); Console.WriteLine( " Available space to current user:{0, 15} bytes", d.AvailableFreeSpace); Console.WriteLine( " Total available space: {0, 15} bytes", d.TotalFreeSpace); Console.WriteLine( " Total size of drive: {0, 15} bytes ", d.TotalSize); } } } } /* This code produces output similar to the following: Drive A:/ File type: Removable Drive C:/ File type: Fixed Volume label: File system: FAT32 Available space to current user: 4770430976 bytes Total available space: 4770430976 bytes Total size of drive: 10731683840 bytes Drive D:/ File type: Fixed Volume label: File system: NTFS Available space to current user: 15114977280 bytes Total available space: 15114977280 bytes Total size of drive: 25958948864 bytes Drive E:/ File type: CDRom The actual output of this code will vary based on machine and the permissions granted to the user executing it. */ |
.NET Framework 安全性
- FileIOPermission 用于访问目录信息。类构造函数需要此权限。关联的枚举: PathDiscovery 。
继承层次结构
System.Object
System.IO.DriveInfo
System.IO.DriveInfo
线程安全
此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。
平台
Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见 系统要求 。
版本信息
.NET Framework
受以下版本支持:2.0请参见
参考
DriveInfo 成员System.IO 命名空间