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: Getting the freespace on a drive
From Wiki
- 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
- Public Shared Function GetFreeSpace(ByVal Drive As String) As Double
- Dim _BytesTotal, _FreeBytes, _FreeBytesAvailable As Long
- Dim _Ans As Long
- _Ans = GetDiskFreeSpaceEx(Drive, _FreeBytesAvailable, _BytesTotal, _FreeBytes)
- If _Ans > 0 Then
- Return BytesToMegabytes(_FreeBytes)
- Else
- Return 0
- 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
Here you pass the driveletter as a parameter something like c: it also works on mapped drives. The value returned is 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.