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 CopyCode image复制代码
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# Copy 图像复制代码
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.
*/

Collapse 图像.NET Framework 安全性

  • FileIOPermission   用于访问目录信息。类构造函数需要此权限。关联的枚举: PathDiscovery 。

Collapse 图像继承层次结构

System.Object
  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 命名空间
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值