Answered by:
Total Hard Disk Drive Space?

Question
-
Hi,
I'm developing a system info application. I've Searched all over internet and only found code for Free Hard Disk space, but not Total hard disk space.
Someone please help...
The code should calculate the Total space of all the drives.
Thank you
Wednesday, February 16, 2011 6:17 PM
Answers
-
Thanks for your reply, but like i stated, i want the total free space from all the drives. All in one label/textbox.
So that, no matter in what system i run it, it gives me the overall Total space.
You want to get system's total disk space instead of getting each volume' s (each partition and each physical drive) total size seperately? Just sum up the totalsize properties of each drive and show with label (as you wanted) like this:
Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Dim allDrives() As IO.DriveInfo = IO.DriveInfo.GetDrives()
Dim totalbytes As Long
Dim d As IO.DriveInfo
For Each d In allDrives
If d.IsReady = True Then
totalbytes += d.TotalSize
End If
Next
Label1.Text = "The system has " & totalbytes & " bytes in total."
End SubHope this helps.
Best regards, Saygılarımla, Onur Güzel
Yazgeliştir Forumları'ndayım.
Microsoft Haber Grupları Profilim (VB.NET)- Marked as answer by Ali Naeem Wednesday, February 16, 2011 7:03 PM
- Edited by Onur Güzel Wednesday, February 16, 2011 7:04 PM
Wednesday, February 16, 2011 6:53 PM
All replies
-
DriveInfo class provides TotalSize and as well as TotalFreeSpace property:
A good example and documentation is here:
http://msdn.microsoft.com/en-us/library/system.io.driveinfo.totalsize.aspxHTH.
Best regards, Saygılarımla, Onur Güzel
Yazgeliştir Forumları'ndayım.
Microsoft Haber Grupları Profilim (VB.NET)- Proposed as answer by John Anthony Oliver Wednesday, February 16, 2011 6:38 PM
Wednesday, February 16, 2011 6:21 PM -
Can you please help me implement this, im new :)
Does this code come under button1.click event?:
Class Test Public Shared Sub Main() Dim allDrives() As DriveInfo = DriveInfo.GetDrives() Dim d As DriveInfo For Each d In allDrives Console.WriteLine("Drive {0}", d.Name) Console.WriteLine(" File type: {0}", d.DriveType) If d.IsReady = True Then Console.WriteLine(" Volume label: {0}", d.VolumeLabel) Console.WriteLine(" File system: {0}", d.DriveFormat) Console.WriteLine( _ " Available space to current user:{0, 15} bytes", _ d.AvailableFreeSpace) Console.WriteLine( _ " Total available space: {0, 15} bytes", _ d.TotalFreeSpace) Console.WriteLine( _ " Total size of drive: {0, 15} bytes ", _ d.TotalSize) End If Next
Thanks
Wednesday, February 16, 2011 6:26 PM -
If you're developing a Winform application, you shouldn't use Console class, you can represent the returned value via any UI control like label, textbox etc.. or simply with MessageBox when you click on a button like this:
Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Dim allDrives() As IO.DriveInfo = IO.DriveInfo.GetDrives()
Dim d As IO.DriveInfo
For Each d In allDrives
If d.IsReady = True Then
MsgBox("Volume: " & d.Name & " has " & _
d.TotalFreeSpace & " bytes free" & " and " & d.TotalSize & " in total.")
End If
Next
End SubHTH.
Best regards, Saygılarımla, Onur Güzel
Yazgeliştir Forumları'ndayım.
Microsoft Haber Grupları Profilim (VB.NET)Wednesday, February 16, 2011 6:38 PM -
Thanks for your reply, but like i stated, i want the total free space from all the drives. All in one label/textbox.
So that, no matter in what system i run it, it gives me the overall Total space.
Wednesday, February 16, 2011 6:44 PM -
Thanks for your reply, but like i stated, i want the total free space from all the drives. All in one label/textbox.
So that, no matter in what system i run it, it gives me the overall Total space.
You want to get system's total disk space instead of getting each volume' s (each partition and each physical drive) total size seperately? Just sum up the totalsize properties of each drive and show with label (as you wanted) like this:
Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Dim allDrives() As IO.DriveInfo = IO.DriveInfo.GetDrives()
Dim totalbytes As Long
Dim d As IO.DriveInfo
For Each d In allDrives
If d.IsReady = True Then
totalbytes += d.TotalSize
End If
Next
Label1.Text = "The system has " & totalbytes & " bytes in total."
End SubHope this helps.
Best regards, Saygılarımla, Onur Güzel
Yazgeliştir Forumları'ndayım.
Microsoft Haber Grupları Profilim (VB.NET)- Marked as answer by Ali Naeem Wednesday, February 16, 2011 7:03 PM
- Edited by Onur Güzel Wednesday, February 16, 2011 7:04 PM
Wednesday, February 16, 2011 6:53 PM -
You want the NTFS total free formatted space.
Renee
Not a C officianadoWednesday, February 16, 2011 6:58 PM -
Thank you, Onur Guzel, Your code worked perfectly :)
Wednesday, February 16, 2011 7:04 PM