mik706
Jun 8th, 2001, 09:56 AM
I am trying to determine the amount of free space on a disk but am losing the plot.
i am trying to use the GetDiskFreeSpace API but to no availe. Could someone please show me how to use this API or suggest a better approch.
Xiquon
Jun 8th, 2001, 11:42 AM
Taken from:
Dan Appleman
Visual Basic Programmer's Guide to the Win32 API
The Authoritative Solution
A great book for any person who uses this usefull api.
Only problem I was getting is an overflow:
TotalBytes = TotalNumberOfClustors * SectorsPerCluster * BytesPerSector
Too many bytes even on a 4 gig drive.
You may want to make it a string and work with it that way?
-Xiquon
Matthew Gates
Jun 8th, 2001, 01:41 PM
Try this:
Private Declare Function GetDiskFreeSpaceEx _
Lib "kernel32" Alias "GetDiskFreeSpaceExA" (Byval _
lpRootPathName As String, lpFreeBytesAvailableToCaller _
As Currency, lpTotalNumberOfBytes As Currency, _
lpTotalNumberOfFreeBytes As Currency) As Long
Private Sub Form_Load()
Dim r As Long, BytesFreeToCalller As Currency, TotalBytes As Currency
Dim TotalFreeBytes As Currency, TotalBytesUsed As Currency
'the drive to find
Const RootPathName = "C:\"
'get the drive's disk parameters
Call GetDiskFreeSpaceEx(RootPathName, BytesFreeToCalller, TotalBytes, TotalFreeBytes)
'show the results, multiplying the returned
'value by 10000 to adjust for the 4 decimal
'places that the currency data type returns.
Me.AutoRedraw = True
Me.Cls
Me.Print
Me.Print " Total Number Of Bytes:", Format$(TotalBytes * 10000, "###,###,###,##0") & " bytes"
Me.Print " Total Free Bytes:", Format$(TotalFreeBytes * 10000, "###,###,###,##0") & " bytes"
Me.Print " Free Bytes Available:", Format$(BytesFreeToCalller * 10000, "###,###,###,##0") & " bytes"
Me.Print " Total Space Used :", Format$((TotalBytes - TotalFreeBytes) * 10000, "###,###,###,##0") & " bytes"
End Sub