Article ID: 147686
Article Last Modified on 3/14/2005
Control Name Property New Value ---------------------------------------------------------------- Command1 Caption Press for Free Space on Drive C Label1 AutoSize True Label2 AutoSize True
#If Win32 Then
Private Declare Function DiskSpaceFree Lib "STKIT432.DLL" Alias _
"DISKSPACEFREE" () As Long
Private Declare Function GetDiskFreeSpace Lib "kernel32" Alias _
"GetDiskFreeSpaceA" ( ByVal lpRootPathName As String, _
lpSectorsPerCluster As Long, lpBytesPerSector As Long, _
lpNumberOfFreeClusters As Long, lpTotalNumberOfClusters As Long) _
As Long
#Else
Private Declare Function DiskSpaceFree Lib "STKIT416.DLL" () As Long
#End If
Private Sub Command1_Click()
Dim free_Space As Long
ChDrive "C:"
' Method I (using the Win16 API).
free_Space = DiskSpaceFree()
Label1.Caption = "(Method I: ) The total free space on Drive C: = " _
& Str$(free_Space) & " bytes"
' Method II (using the Win32 API).
#If Win32 Then
Dim numSectorsPerCluster As Long
Dim numBytesPerSector As Long
Dim numFreeClusters As Long
Dim numTotalClusters As Long
Dim success As Boolean
success = GetDiskFreeSpace("C:\", numSectorsPerCluster, _
numBytesPerSector, numFreeClusters, numTotalClusters)
free_Space = numSectorsPerCluster * numBytesPerSector * _
numFreeClusters
Label2.Caption = _
"(Method II:) The total free space on Drive C: = " & _
Str$(free_Space) & " bytes"
#Else
Label2.Caption = "Use Method I for Win16 applications"
#End If
End Sub
Keywords: kbhowto kbsetup KB147686