Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Community Wiki

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.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

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

Navigation

Google Ads

VB.Net: Get the total space used by a drive

From Wiki

Jump to: navigation, search
  1. Public Shared Function GetTotalSpace(ByVal Drive As String) As String
  2.             Dim _BytesTotal, _FreeBytes, _FreeBytesAvailable As Long
  3.             Dim _Ans As Long
  4.             _Ans = GetDiskFreeSpaceEx(Drive, _FreeBytesAvailable, _
  5.                  _BytesTotal, _FreeBytes)
  6.             If _Ans > 0 Then
  7.                 Return BytesToMegabytes(_BytesTotal).ToString
  8.             Else
  9.                 Throw New Exception("Invalid or unreadable drive")
  10.             End If
  11.         End Function
  12.  
  13. Private Shared Function BytesToMegabytes(ByVal Bytes As Long) As Double
  14.             Dim _MBs As Double
  15.             _MBs = (Bytes / 1024) / 1024
  16.             Return _MBs
  17.         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.

382 Rating: 1.0/5 (3 votes cast)