从硬盘查找所有驱动器大小 [英] Finding All Drive Size From Hard disk

查看:138
本文介绍了从硬盘查找所有驱动器大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
有谁能告诉我如何找到硬盘中所有驱动器的大小? :doh:

Hi All,
Can any tell me how to find size of all drives present in my Hard disk? :doh:

推荐答案

您是说您的硬盘具有多个分区,并且想知道每个分区的大小,还是只是想知道您计算机中硬盘的大小?

如果是后者,那么我怀疑您没有费心去寻找答案.简单搜索 c#驱动器大小将为您提供许多解决方案.
Do you mean that you have a Hard Disk with several partitions and you want to know the size of each partition, or do you simply want to know the sizes of the Hard Disks in your computer?

If the latter then I suspect that you have not bothered to search for the answer to this. A simple search on c# drive size will get you lots of solutions.


这里是^ ]链接.互联网上有很多可用的方法.
Here is one[^] link. There are plenty of them available on the internet for this.


在这里,我们去...
我只用一个名为"lboxDrives"的形式的列表框控件,然后在一个名为"Info"的按钮上编写了以下代码:


Here we go...
i just take one listbox control in my form named it "lboxDrives" ,then on one button named "Info" following code is written:


private void btnDriveInfo_Click(object sender, EventArgs e)
       {
           string[] GetDrives = Environment.GetLogicalDrives();
               if (lboxDrives.Items.Count > 0)
               return;
           foreach (string  item in GetDrives )
           {

               string drive;
               drive = item;
               DriveInfo GetInfo = new DriveInfo(item);
               if (GetInfo.DriveType == DriveType.CDRom || GetInfo.DriveType == DriveType.Network)
               {

                   continue;

               }


               long freeSpace = GetInfo.AvailableFreeSpace;
               double freeSpaceinGB = freeSpace / (1024 * 1024 * 1024);
               drive += "("+freeSpaceinGB+" GB Free)";
               lboxDrives.Items.Add(drive);
                         }


这篇关于从硬盘查找所有驱动器大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆