Returns the number of free bytes for a drive : Drive « File Path « VBA / Excel / Access / Word






Returns the number of free bytes for a drive

 

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

Sub FreeDiskSpace()
    Dim SectorsPerCluster As Long
    Dim BytesPerSector As Long
    Dim NumberofFreeClusters As Long
    Dim TotalClusters As Long

    x = GetDiskFreeSpace("c:\", SectorsPerCluster, _
      BytesPerSector, NumberofFreeClusters, TotalClusters)
    
    If x = 0 Then 'Error occurred
        Exit Sub
    End If
    Debug.Print SectorsPerCluster
    Debug.Print BytesPerSector
    Debug.Print NumberofFreeClusters
End Sub

 








Related examples in the same category

1.Get Drive Information
2.The TypeOfDrive Function
3.The NumberOfBytesFree Function
4.Returns the total storage capacity for a drive
5.Returns a string that describes the drive type
6.Returns True if a specified drive letter exists
7.Returns the number of drives
8.Returns the drive letter using an index
9.Display Drive information