DriveInfo類的基本操作

iamzxf發表於2015-06-03
       DriveInfo類:提供查詢驅動器資訊的方法和屬性,通過下面的例子來說明。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace DriveInfoDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            DriveInfo[] allDrives = DriveInfo.GetDrives();
            foreach (DriveInfo d in allDrives)
            {
                Console.WriteLine("驅動器:{0}",d.Name);
                Console.WriteLine("型別:{0}",d.DriveType);
                if (d.IsReady)
                {
                    Console.WriteLine("卷標:{0}", d.VolumeLabel);
                    Console.WriteLine("檔案系統:{0}", d.DriveFormat);
                    Console.WriteLine("當前可用空間:{0}", d.AvailableFreeSpace);
                    Console.WriteLine("可用空間:{0}",d.TotalFreeSpace);
                    Console.WriteLine("磁碟總大小:{0}",d.TotalSize);
                }
            }

            Console.ReadLine();
        }
    }
}