C#获取硬盘信息

 1     /// <summary>
2 /// 硬盘
3 /// </summary>
4 public class VAV_MDDFM_HD
5 {
6 private static StringBuilder strBu = new StringBuilder();
7
8 /// <summary>
9 /// 获取硬盘空间大小
10 /// </summary>
11 /// <param name="Drive">指定盘符,默认为ALL</param>
12 public static string Get_HD_Space(string Drive)
13 {
14 Dictionary<string, object> dicts = Get_HD_Space();
15 if (Drive.Trim().Length <= 0)
16 return strBu.ToString();
17 object o = null;
18 foreach (string key in dicts.Keys)
19 {
20
21 if (dicts.ContainsKey(Drive.ToLower()))
22 {
23 o = dicts[Drive.ToLower()];
24 break;
25 }
26
27 Console.WriteLine(dicts[key]);
28 }
29 return o.ToString();
30 }
31 /// <summary>
32 /// 打印硬盘空间大小
33 /// </summary>
34 /// <param name="Drive">指定盘符,默认为ALL</param>
35 public static void Print_HD_Space(string Drive)
36 {
37 Console.WriteLine(Get_HD_Space(Drive));
38 }
39
40 /// <summary>
41 /// 获取硬盘空间大小
42 /// </summary>
43 public static Dictionary<string, object> Get_HD_Space()
44 {
45 DriveInfo[] allDrives = DriveInfo.GetDrives();
46
47 Dictionary<string, object> dict = new Dictionary<string, object>();
48
49 StringBuilder sb = new StringBuilder();
50
51 foreach (DriveInfo d in allDrives)
52 {
53 sb = new StringBuilder();
54 //Console.WriteLine("Drive {0}", d.Name);
55 sb.Append(string.Format(" Drive {0}", d.Name.ToLower()));
56 //Console.WriteLine(" File type: {0}", d.DriveType);
57 sb.Append(string.Format(" File type: {0}", d.DriveType));
58 if (d.IsReady == true)
59 {
60 sb.Append(string.Format("Volume label: {0}{1}", d.VolumeLabel, "\r\n"));
61 sb.Append(string.Format("File system: {0}{1}", d.DriveFormat, "\r\n"));
62 sb.Append(string.Format("Available space to current user:{0, 15} GB{1}", Utility.ConvertBytes(d.AvailableFreeSpace.ToString(), 3), "\r\n"));
63 sb.Append(string.Format("Total available space: {0, 15} GB{1}", Utility.ConvertBytes(d.TotalFreeSpace.ToString(), 3), "\r\n"));
64 sb.Append(string.Format("Total size of drive: {0, 15} GB{1}", Utility.ConvertBytes(d.TotalSize.ToString(), 3), "\r\n"));
65 }
66
67 strBu.Append(sb + "\r\n");
68
69 dict.Add(d.Name, sb);
70 }
71 return dict;
72 }
73 }

 

转载于:https://www.cnblogs.com/-ShiL/archive/2012/03/19/2406918.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值