Click here to Skip to main content
15,914,419 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
Can any tell me how to find size of all drives present in my Hard disk? :doh:
Posted
Updated 9-Jun-10 1:09am
v2

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.
 
Share this answer
 
Here is one[^] link. There are plenty of them available on the internet for this.
 
Share this answer
 
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:


C#
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);
                         }
 
Share this answer
 
You can use the DriveInfo class:

C#
double totalhddsize = 0;
foreach (DriveInfo info in DriveInfo.GetDrives())
{
    if (info.IsReady && info.DriveType == DriveType.Fixed)
    {
        totalhddsize += info.TotalSize;
    }
}


But be aware that it might take sometime with big disks to get the size so it's preferred to use a BackgroundWorker to avoid your program to be not responding for a while.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900