C#得到磁碟資訊

來源:互聯網
上載者:User
1、代碼  代碼

System.IO.DriveInfo[] drive = System.IO.DriveInfo.GetDrives();
            for (int i = 0; i < drive.Length; i++)
            {
                if (drive[i].DriveType == DriveType.Fixed)
                {
                    dsmch = drive[i].Name;
                    double tmp = drive[i].TotalSize / 1024 / 1024 / 1024 * 100;
                    tmp = format.Round(tmp, 2) / 100;
                    zhrl = tmp.ToString();
                    tmp = drive[i].AvailableFreeSpace / 1024 / 1024 / 1024 * 100;
                    tmp = format.Round(tmp, 2) / 100;
                    kyrl = tmp.ToString();
                    Sql = "insert diskdoc(dsmch,zhrl,kyrl) ";
                    Sql += "values('" + dsmch + "','" + zhrl + "','" + kyrl + "')";
                    cmd = new SqlCommand(Sql, SqlCon);
                    cmd.ExecuteNonQuery();
                }
            }

2、說明

name: 盤符

TotalFreeSpace:返回磁碟可用空間,傳回值類型long。

DriveType:磁碟類型  傳回值如下:

CDRom(光碟機)、Fixed(固定磁碟)、Unknown(未知磁碟)、Network(網路磁 盤)、NoRootDirectory(盤符不存在)、Ram(虛擬磁碟)、Removable(可移動磁碟)。

IsReady:擷取一個指示磁碟機是否已準備好的值  返回bool類型。

RootDirectory:擷取磁碟機根目錄。

TotalSize : 空間總大小。

VolumeLabel: 擷取磁碟機卷標,返回string類型。

DriveFormat:   擷取檔案系統的名稱,例如 NTFS 或 FAT32。 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.