I have code to find FreeSpace of a drive but i need to modify it and get the TotalSpace of the drive. I need help with modification. Here is the code for FreeSpace:
'**************************************
'Windows API/Global Declarations for :Ge
' tDiskFreeSpaceEx
'**************************************
Private Type ULong ' Unsigned Long
Byte1 As Byte
Byte2 As Byte
Byte3 As Byte
Byte4 As Byte
End Type
Private Type LargeInt ' Large Integer
LoDWord As ULong
HiDWord As ULong
LoDWord2 As ULong
HiDWord2 As ULong
End Type
Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias "GetDiskFreeSpaceExA" _
(ByVal lpRootPathName As String, FreeBytesAvailableToCaller As LargeInt, _
TotalNumberOfBytes As LargeInt, TotalNumberOfFreeBytes As LargeInt) As Long
' Inputs
ass any valid path to the GetF
' reeSpace function. The path could be a l
' ocal drive ("c:" or "c:\windows"
, netwo
' rk drive ("x:" or "x:\MyFolder"
or UNC
' path like "\\myserver\myshare".
'
' Returns:GetFreeSpace function returns
' total number of free bytes on the disk t
' hat are available to the user associated
' with the calling thread. Return value is
' a Double.
'**************************************
Function GetFreeSpace(strPath As String) As Double
Dim nFreeBytesToCaller As LargeInt
Dim nTotalBytes As LargeInt
Dim nTotalFreeBytes As LargeInt
strPath = Trim(strPath)
If Right(strPath, 1) <> "\" Then
strPath = strPath & "\"
End If
If GetDiskFreeSpaceEx(strPath, nFreeBytesToCaller, nTotalBytes, nTotalFreeBytes) <> 0 Then
GetFreeSpace = CULong( _
nFreeBytesToCaller.HiDWord.Byte1, _
nFreeBytesToCaller.HiDWord.Byte2, _
nFreeBytesToCaller.HiDWord.Byte3, _
nFreeBytesToCaller.HiDWord.Byte4) * 2 ^ 32 + _
CULong(nFreeBytesToCaller.LoDWord.Byte1, _
nFreeBytesToCaller.LoDWord.Byte2, _
nFreeBytesToCaller.LoDWord.Byte3, _
nFreeBytesToCaller.LoDWord.Byte4)
End If
End Function
Function CULong(Byte1 As Byte, Byte2 As Byte, Byte3 As Byte, Byte4 As Byte) As Double
CULong = Byte4 * 2 ^ 24 + Byte3 * 2 ^ 16 + Byte2 * 2 ^ 8 + Byte1
End Function
'**************************************
'Windows API/Global Declarations for :Ge
' tDiskFreeSpaceEx
'**************************************
Private Type ULong ' Unsigned Long
Byte1 As Byte
Byte2 As Byte
Byte3 As Byte
Byte4 As Byte
End Type
Private Type LargeInt ' Large Integer
LoDWord As ULong
HiDWord As ULong
LoDWord2 As ULong
HiDWord2 As ULong
End Type
Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias "GetDiskFreeSpaceExA" _
(ByVal lpRootPathName As String, FreeBytesAvailableToCaller As LargeInt, _
TotalNumberOfBytes As LargeInt, TotalNumberOfFreeBytes As LargeInt) As Long
' Inputs
' reeSpace function. The path could be a l
' ocal drive ("c:" or "c:\windows"
' rk drive ("x:" or "x:\MyFolder"
' path like "\\myserver\myshare".
'
' Returns:GetFreeSpace function returns
' total number of free bytes on the disk t
' hat are available to the user associated
' with the calling thread. Return value is
' a Double.
'**************************************
Function GetFreeSpace(strPath As String) As Double
Dim nFreeBytesToCaller As LargeInt
Dim nTotalBytes As LargeInt
Dim nTotalFreeBytes As LargeInt
strPath = Trim(strPath)
If Right(strPath, 1) <> "\" Then
strPath = strPath & "\"
End If
If GetDiskFreeSpaceEx(strPath, nFreeBytesToCaller, nTotalBytes, nTotalFreeBytes) <> 0 Then
GetFreeSpace = CULong( _
nFreeBytesToCaller.HiDWord.Byte1, _
nFreeBytesToCaller.HiDWord.Byte2, _
nFreeBytesToCaller.HiDWord.Byte3, _
nFreeBytesToCaller.HiDWord.Byte4) * 2 ^ 32 + _
CULong(nFreeBytesToCaller.LoDWord.Byte1, _
nFreeBytesToCaller.LoDWord.Byte2, _
nFreeBytesToCaller.LoDWord.Byte3, _
nFreeBytesToCaller.LoDWord.Byte4)
End If
End Function
Function CULong(Byte1 As Byte, Byte2 As Byte, Byte3 As Byte, Byte4 As Byte) As Double
CULong = Byte4 * 2 ^ 24 + Byte3 * 2 ^ 16 + Byte2 * 2 ^ 8 + Byte1
End Function