How to get Total Disk Space for a given drive
Posted on January 4, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 'System & API - How to get Total Disk Space for a given drive Option Explicit Private Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" _ (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, _ lpNumberOfFreeClusters As Long, lpTotalNumberOfClusters As Long) As Long Public Function GetTotalDiskSpace(Drive As String) As Single Dim lngSectors_per_cluster As Long Dim lngBytes_per_sector As Long Dim lngFree_clusters As Long Dim lngTotal_clusters As Long If GetDiskFreeSpace(Drive, lngSectors_per_cluster, lngBytes_per_sector, lngFree_clusters, _ lngTotal_clusters) = 0 Then GetTotalDiskSpace = -1 Else GetTotalDiskSpace = Format(((lngTotal_clusters / 1000000) * lngSectors_per_cluster * _ lngBytes_per_sector), "##,###.00") End If End Function 'How can I call this function: 'Call MsgBox("The Total Disk Space of C Drive is " & GetTotalDiskSpace("C:") & " MB.", vbInformation, App.Title) |