DriveInfo 类.NET Framework 4 提供对有关驱动器的信息的访问。 System.Object 命名空间: System.IO C# [SerializableAttribute] [ComVisibleAttribute(true)] public sealed class DriveInfo : ISerializable DriveInfo 类型公开以下成员。
此类对驱动器进行建模,并提供方法和属性以查询驱动器信息。 使用 DriveInfo 来确定哪些驱动器可用,以及这些驱动器的类型。 还可以通过查询来确定驱动器的容量和可用空闲空间。 下面的代码示例演示如何使用 DriveInfo 类显示有关当前系统中所有驱动器的信息。 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); } } } } |
DriveInfo 类
最新推荐文章于 2024-04-30 22:56:29 发布