Library code snippets

Get Free Disk Space On Large Drives

This code will allow you get the free disk space on a drive which is over 2 Gb in size. Put all this code into a module

Public Type LargeInt
  lngLower As Long
  lngUpper As Long
End Type

Public Declare Function GetDiskFreeSpaceEx Lib "kernel32.dll" Alias "GetDiskFreeSpaceExA" (ByVal lpDirectoryName As String, lpFreeBytesAvailableToCaller As LargeInt, lpTotalNumberOfBytes As LargeInt, lpTotalNumberofFreeBytes As LargeInt) As Long



Public Function FreeDiskSpace(ByVal sDriveLetter As String) As Double
'---------------------------------------------------------------------------------------
' Procedure : FreeDiskSpace
' DateTime  : 02/01/2004 12:20
' Author    : Luke
' Purpose   : Returns Free Disk Space using LARGE INT method (Over 2Gb Drives)
'---------------------------------------------------------------------------------------
'


Dim udtFreeBytesAvail As LargeInt, udtTtlBytes As LargeInt
Dim udtTTlFree As LargeInt
Dim dblFreeSpace As Double

If GetDiskFreeSpaceEx(sDriveLetter, udtFreeBytesAvail, udtTtlBytes, udtTTlFree) Then
       
        If udtFreeBytesAvail.lngLower < 0 Then
           dblFreeSpace = udtFreeBytesAvail.lngUpper * 2 ^ 32 + udtFreeBytesAvail.lngLower + 4294967296#
        Else
           dblFreeSpace = udtFreeBytesAvail.lngUpper * 2 ^ 32 + udtFreeBytesAvail.lngLower
        End If

End If

FreeDiskSpace = dblFreeSpace

End Function

To use this new module just declare a variable as a double then do this:

Dim dFreeSpace as double

dFreeSpace = FreeDiskSpace("C:\")

Thats it. You will get a value which equals the number of bytes of free space.

Comments

  1. 11 Sep 2008 at 11:48

    I think System.IO.DriveInfo mite be better to use nowadays

    http://msdn.microsoft.com/en-us/library/system.io.driveinfo.aspx

  2. 04 Aug 2008 at 18:03

    Perfect routine did exactly what I needed

  3. 01 Jan 1999 at 00:00

    This thread is for discussions of Get Free Disk Space On Large Drives.

Leave a comment

Sign in or Join us (it's free).

Luke Lesurf Erm I went to school, then college and then i got a job... In programming. I like to fly planes and go fishing. I dont like brussle sprouts or cabbage. Love walker's squares. And coke (as in cola)

Related discussion

Related podcasts

  • Christian Beauclair

    14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...

Want to stay in touch with what's going on? Follow us on twitter!