1. 程式人生 > >C#通過碟符獲取剩餘空間

C#通過碟符獲取剩餘空間

  public static long GetHardDiskSpace(string str_HardDiskName)
        {
            long totalSize = 0;
            str_HardDiskName = str_HardDiskName + ":\\";
            DriveInfo[] drives = DriveInfo.GetDrives();
            foreach (DriveInfo drive in drives)
            {
                if (drive.Name == str_HardDiskName)
                {
                    totalSize 
= drive.TotalFreeSpace *100/ drive.TotalSize; } } return totalSize; }

使用方法: 傳如引數C 、D、 E、 F等碟符的名字。