Library code snippets
Get Free Disk Space On Large Drives
By Luke Lesurf, published on 02 Jan 2004
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.
Related articles
Related discussion
-
Problem with migration to C# (CoCreateInstanceEx)
by LRollison (1 replies)
-
VB6 Problem Creating Shortcuts
by rb1177 (0 replies)
-
how can i open a file
by kyawswarhtun (0 replies)
-
how to save any one form what i want?
by blackguy (5 replies)
-
Build an MP3 Player
by soybees (4 replies)
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...
I think System.IO.DriveInfo mite be better to use nowadays
http://msdn.microsoft.com/en-us/library/system.io.driveinfo.aspx
Perfect routine did exactly what I needed
This thread is for discussions of Get Free Disk Space On Large Drives.