Visual Basic 6 function "disk_total_space"

Go back

Below you'll find the source for the Visual Basic 6 function disk_total_space.

Attribute VB_Name = "modDiskTotalSpace"
' This function is downloaded from:
' http://www.stefanthoolen.nl/archive/vb6-functions/
' 
' You may freely distribute this file but please leave all comments, including this one, in it.
' 
' @Author Stefan Thoolen <mail@stefanthoolen.nl>

Option Explicit

Private Declare Function GetDiskFreeSpaceA Lib "kernel32" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTotalNumberOfClusters As Long) As Long

''
' Returns the total size of a directory
' Same syntax as the PHP function 'disk_total_space'
' See also: http://www.php.net/manual/en/function.disk-total-space.php
' @param    Variant directory       The path of which we want to know the total space
' @return   Double                  The amount of total bytes
' @author   Stefan Thoolen <mail@stefanthoolen.nl>
Public Function disk_total_space(directory As Variant) As Double
    Dim sectorspercluster As Long, bytespersector As Long, numberoffreeclusters As Long, numberofclusters As Long
    Dim bytespercluster As Double
    
    GetDiskFreeSpaceA directory, sectorspercluster, bytespersector, numberoffreeclusters, numberofclusters
    bytespercluster = sectorspercluster * bytespersector
    
    disk_total_space = bytespercluster * numberofclusters
End Function