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 derfloh 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

Status
Not open for further replies.

Hpatel

IS-IT--Management
Apr 3, 2001
21
US
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: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
 
The FileSystem object does an admirable job of performing that task. Is there a reason you prefer to use the API?
VCA.gif

Alt255@Vorpalcom.Intranets.com​
 
Alt255, thanks for your help. filesystem object did the job. Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top