2016-04-12
Visual Studio 2015
using System; using System.Windows.Forms; using System.IO; namespace AllDiskSize { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { GetDeveiceSize(); } private void GetDeveiceSize() { //取得所有磁碟機的DriveInfo類別 DriveInfo[] ListDrivesInfo = DriveInfo.GetDrives(); try { foreach (DriveInfo vListDrivesInfo in ListDrivesInfo) { //使用IsReady屬性判斷裝置是否就緒 if (vListDrivesInfo.IsReady) { richTextBox1.AppendText("磁碟代號:" + vListDrivesInfo.Name + "\n"); richTextBox1.AppendText("磁碟標籤: " + vListDrivesInfo.VolumeLabel + "\n"); richTextBox1.AppendText("磁碟類型:" + vListDrivesInfo.DriveType.ToString() + "\n"); richTextBox1.AppendText("磁碟格式:" + vListDrivesInfo.DriveFormat + "\n"); richTextBox1.AppendText("磁碟大小:" + vListDrivesInfo.TotalSize.ToString("#,#") + "\n"); // 千分位顯示 richTextBox1.AppendText("剩餘空間:" + vListDrivesInfo.AvailableFreeSpace.ToString("#,#") + "\n"); richTextBox1.AppendText("總剩餘空間(含磁碟配碟):" + vListDrivesInfo.TotalFreeSpace.ToString("#,#") + "\n"); richTextBox1.AppendText("=================================\n"); } } } catch (Exception ex) { Console.WriteLine("ex:" + ex.Message); } } } } |
執行結果
磁碟代號:C:\
磁碟標籤: 磁碟類型:Fixed 磁碟格式:NTFS 磁碟大小:125,304,827,904 剩餘空間:39,481,905,152 總剩餘空間(含磁碟配碟):39,481,905,152 ================================= 磁碟代號:D:\ 磁碟標籤: 磁碟類型:Fixed 磁碟格式:NTFS 磁碟大小:374,275,567,616 剩餘空間:9,067,077,632 總剩餘空間(含磁碟配碟):9,067,077,632 ================================= |
(完)
沒有留言:
張貼留言