• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C#获取硬盘信息

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
 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 }

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
[转]C#线程知识--使用Task执行异步操作发布时间:2022-07-14
下一篇:
正则表达式(Java,C#,C++)发布时间:2022-07-14
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap