C# 读取驱动器盘符及信息

 1 System.IO.DriveInfo[] hardDiskDrives = System.IO.DriveInfo.GetDrives();
 2             foreach (System.IO.DriveInfo hardDiskDrive in hardDiskDrives)
 3             {
 4                 if(hardDiskDrive.DriveType.ToString() != "CDRom")
 5                 {
 6                     totalSize = hardDiskDrive.TotalSize / (1024 * 1024 * 1024);
 7                     totalFreeSpace = hardDiskDrive.TotalFreeSpace / (1024 * 1024 * 1024);
 8                     textBoxDisksVolumn.Text += hardDiskDrive.Name + " " + totalSize.ToString() + "GB   ";
 9                     textBoxAvalaibleSpace.Text += hardDiskDrive.Name + " " + totalFreeSpace.ToString() + "GB   ";
10                 } 
11             }

 

posted @ 2014-08-24 17:02  瘋子朱磊  阅读(279)  评论(0编辑  收藏  举报