954,551 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Need code to get free space and used space in hard drive ..

Hi Friends..

I need to get the free space and used space in hard drive ..Can anyone provide me with the code..I need the code in VB.net..I need to see the space available in each drive individually..
Someone help in this regard as early as possible..

Regards,
Balagurunathan

BalagurunathanS
Light Poster
26 posts since Apr 2007
Reputation Points: 10
Solved Threads: 0
 

Try this:

Dim dvr As New DriveInfo("c:")
        Label1.Text = CStr(dvr.TotalFreeSpace / 1000000) & " MB"
        Label2.Text = CStr(dvr.TotalSize / 1000000) & " MB"
        Label3.Text = CStr(Val(Label2.Text) - Val(Label1.Text)) & " MB"
waynespangler
Posting Pro in Training
461 posts since Dec 2002
Reputation Points: 84
Solved Threads: 58
 

This is slightly modified from the VB 2005 .NET help files. lstInfo is a listbox in my test application.

Dim alldrives() As DriveInfo = DriveInfo.GetDrives()
        Dim d As DriveInfo

        For Each d In alldrives
            lstInfo.Items.Add(String.Format( _
                "Drive {0}", d.Name))
            lstInfo.Items.Add(String.Format( _
                "  File type: {0}", d.DriveType))

            If d.IsReady = True Then
                lstInfo.Items.Add(String.Format( _
                    "  Volume label: {0}", d.VolumeLabel))
                lstInfo.Items.Add(String.Format( _
                    "  File system: {0}", d.DriveFormat))
                lstInfo.Items.Add(String.Format( _
                    "  Available space to current user:{0, 12:N0} Mbytes", _
                    d.AvailableFreeSpace >> 20))

                lstInfo.Items.Add(String.Format( _
                    "  Total available space:          {0, 12:N0} Mbytes", _
                    d.TotalFreeSpace >> 20))

                lstInfo.Items.Add(String.Format( _
                    "  Total size of drive:            {0, 12:N0} Mbytes ", _
                    d.TotalSize >> 20))
            End If
        Next
scottb2
Newbie Poster
12 posts since Sep 2007
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You