提供对有关驱动器的信息的访问。

System.Object
  System.IO.DriveInfo

 

命名空间:  System.IO
程序集:  mscorlib(在 mscorlib.dll 中)
复制
[SerializableAttribute]
[ComVisibleAttribute(true)]
public sealed class DriveInfo : ISerializable

DriveInfo 类型公开以下成员。

  名称 说明
DriveInfo 提供对有关指定驱动器的信息的访问。
  名称 说明
AvailableFreeSpace 指示驱动器上的可用空闲空间量。
DriveFormat 获取文件系统的名称,例如 NTFS 或 FAT32。
DriveType 获取驱动器类型。
IsReady 获取一个指示驱动器是否已准备好的值。
Name 获取驱动器的名称。
RootDirectory 获取驱动器的根目录。
TotalFreeSpace 获取驱动器上的可用空闲空间总量。
TotalSize 获取驱动器上存储空间的总大小。
VolumeLabel 获取或设置驱动器的卷标。
页首
  名称 说明
Equals(Object) Object。)
Finalize Object。)
GetDrives 检索计算机上的所有逻辑驱动器的驱动器名称。
GetHashCode Object。)
GetType Object。)
MemberwiseClone Object。)
ToString Object.ToString。)
页首
  名称 说明
ISerializable.GetObjectData SerializationInfo 对象。
页首

还可以通过查询来确定驱动器的容量和可用空闲空间。

DriveInfo 类显示有关当前系统中所有驱动器的信息。

复制
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);
            }
        }
    }
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-05
  • 2021-10-24
猜你喜欢
  • 2022-01-10
  • 2021-09-11
  • 2021-08-08
  • 2021-12-02
  • 2022-12-23
  • 2021-07-14
相关资源
相似解决方案