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

Recommended Answers

All 3 Replies

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"

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.