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:
' You may freely distribute this file but please leave all comments, including this one, in it.
' @Author Stefan Thoolen <>

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:
' @param    Variant directory       The path of which we want to know the free space
' @return   Double                  The amount of available bytes
' @author   Stefan Thoolen <>
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