PBDR.COM

About   -   Contact   -   Purchase   -   Search   -   What's New

 
 
Get Total Disk Space
This function returns number of Mbytes of total disk space when passed the drive letter to be interrogated. Add the following code to a FileHandling.bas standard module to compile a File Utility function set:
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
'*******************************************************
'<DESC>		Interrogates total disk space in
'		Mbytes on specified drive</DESC>
'<RETURN>	Drive capacity (Mb)
'			</RETURN>
'<ACCESS>	Public
'<ARGS>		Drive to Interrogate
'				</ARGS>
'<USAGE>	sngDriveSpace = GetTotalDiskSpace("c:\")
'				</USAGE>
'*******************************************************
  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
    
 

Top of Page

Legal Notice

Ken Howe 2011