Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TotalSpace code modification 1

Status
Not open for further replies.

Hpatel

IS-IT--Management
Apr 3, 2001
21
US
I have code that will find the FreeSpace of a drive but i need help with modification of this code to fet the TOTALSPACE of the drive. Here is the Code:

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:pass 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) <> &quot;\&quot; Then
strPath = strPath & &quot;\&quot;
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

Thank you
 
Though it's not really consistant with the rest of your code, the FileSystemObject exposes a Drive object that has a TotalSize Property. If you decide to go this route instead of using API's, you'll also find the FreeSpace property useful.

If you have any questions on using the FileSystemObject, just let me know
 
ToddR, thanks for your help. FileSystemObject did the job thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top