Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.
VB.Net: Get the total space used by a drive
From Wiki
- Public Shared Function GetTotalSpace(ByVal Drive As String) As String
- Dim _BytesTotal, _FreeBytes, _FreeBytesAvailable As Long
- Dim _Ans As Long
- _Ans = GetDiskFreeSpaceEx(Drive, _FreeBytesAvailable, _
- _BytesTotal, _FreeBytes)
- If _Ans > 0 Then
- Return BytesToMegabytes(_BytesTotal).ToString
- Else
- Throw New Exception("Invalid or unreadable drive")
- End If
- End Function
- Private Shared Function BytesToMegabytes(ByVal Bytes As Long) As Double
- Dim _MBs As Double
- _MBs = (Bytes / 1024) / 1024
- Return _MBs
- End Function
You pass the driveletter as the parameter and it will give you the totalspace of a drive used, also works for mapped drives. Returns the value in MB.



LTD Social Sitings
Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.