Everytime
Aug 13th, 2001, 03:29 AM
Does anyone know how to programatically get the total disk space and total disk space free? Cheers
everytime
crispin
Aug 13th, 2001, 03:34 AM
FROM WWW.ALLAPI.NET:
Create a new project, and add this code to Form1:
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
Everytime
Aug 13th, 2001, 03:38 AM
Found it....
' Declarations and such needed for the example:
' (Copy them to the (declarations) section of a module.)
Public Type ULARGE_INTEGER
LowPart As Long
HighPart As Long
End Type
Public Declare Function GetDiskFreeSpaceEx Lib "kernel32.dll" Alias "GetDiskFreeSpaceExA" (ByVal _
lpDirectoryName As String, lpFreeBytesAvailableToCaller As ULARGE_INTEGER, _
lpTotalNumberOfBytes As ULARGE_INTEGER, lpTotalNumberOfFreeBytes As ULARGE_INTEGER) As Long
Public Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source _
As Any, ByVal Length As Long)
' *** Place the following code inside the form window. ***
Private Sub Command1_Click()
Dim userbytes As ULARGE_INTEGER ' bytes free to user
Dim totalbytes As ULARGE_INTEGER ' total bytes on disk
Dim freebytes As ULARGE_INTEGER ' free bytes on disk
Dim tempval As Currency ' display buffer for 64-bit values
Dim retval As Long ' generic return value
' Get information about the C: drive.
retval = GetDiskFreeSpaceEx("C:\", userbytes, totalbytes, freebytes)
' Copy freebytes into the Currency data type.
CopyMemory tempval, freebytes, 8
' Multiply by 10,000 to move Visual Basic's decimal point to the end of the actual number.
tempval = tempval * 10000
' Display the amount of free space on C:.
Debug.Print "Free Space on the C: drive:"; tempval; "bytes"
End Sub
Everytime
Aug 13th, 2001, 03:48 AM
cheers for efforts crispin