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: Getting the freespace on a drive

From Wiki

Jump to: navigation, search
  1. Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias "GetDiskFreeSpaceExA" (ByVal lpDirectoryName As String, ByRef lpFreeBytesAvailableToCaller As Long, ByRef lpTotalNumberOfBytes As Long, ByRef lpTotalNumberOfFreeBytes As Long) As Long
  2.  
  3. Public Shared Function GetFreeSpace(ByVal Drive As String) As Double
  4.    Dim _BytesTotal, _FreeBytes, _FreeBytesAvailable As Long
  5.    Dim _Ans As Long
  6.    _Ans = GetDiskFreeSpaceEx(Drive, _FreeBytesAvailable, _BytesTotal, _FreeBytes)
  7.    If _Ans > 0 Then
  8.       Return BytesToMegabytes(_FreeBytes)
  9.    Else
  10.       Return 0
  11.    End If
  12. End Function
  13.  
  14. Private Shared Function BytesToMegabytes(ByVal Bytes As Long) As Double
  15.    Dim _MBs As Double
  16.    _MBs = (Bytes / 1024) / 1024
  17.    Return _MBs
  18. End Function

Here you pass the driveletter as a parameter something like c: it also works on mapped drives. The value returned is in MB.

380 Rating: 1.3/5 (3 votes cast)