Visual Basic 6 function "disk_free_space"

Go back

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

Attribute VB_Name = "modDiskFreeSpace"
' 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 available space in directory
' Same syntax as the PHP function 'disk_free_space'
' See also: http://www.php.net/manual/en/function.disk-free-space.php
' @param    Variant directory       The path of which we want to know the free space
' @return   Double                  The amount of available bytes
' @author   Stefan Thoolen <mail@stefanthoolen.nl>
Public Function disk_free_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_free_space = bytespercluster * numberoffreeclusters
End Function