Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 19,651 times

Related Categories

Get Free Disk Space On Large Drives

phracker76

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.

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)

Comments