Make your own free website on

Get Disk Capacity, Free And Used Space

'Add a module to your project (In the menu choose Project -> Add Module, Then click Open)
'Insert the following code to your module:

Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" _
(ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector _
As Long, lpNumberOfFreeClusters As Long, lpTtoalNumberOfClusters As Long) As Long

'Insert the following code to your form:

Private Sub Form_Load()
'Replace the 'c:\' below with the drive you want to get his information
result = GetDiskFreeSpace("c:\", lspc, lbps, lnofc, ltnoc)
If result = 0 Then MsgBox "There was An Error!"
MyCapacity = lspc * lbps * ltnoc
MyFree = lspc * lbps * lnofc
MyUsed = MyCapacity - MyFree
MsgBox "Capacity: " & MyCapacity & " Bytes"
MsgBox "Free: " & MyFree & " Bytes"
MsgBox "Used: " & MyUsed & " Bytes"
End Sub

Go Back