Page 1 of 1

How to get free space of a disk

Posted: Fri Oct 30, 2009 11:47 am
by Cyclops

Code: Select all


Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias "GetDiskFreeSpaceExA" (ByVal lpRootPathName As String, lpFreeBytesAvailableToCaller As Currency, lpTotalNumberOfBytes As Currency, lpTotalNumberOfFreeBytes As Currency) As Long

Public Function GetFreeSpace(ByVal Drive As String) As Currency
        
    Dim BytesFreeToCalller As Currency
    Dim TotalBytes As Currency
    Dim TotalFreeBytes As Currency
        
    If Right(Drive, 1) <> "\" Then Drive = Drive & "\"
    GetDiskFreeSpaceEx Drive, BytesFreeToCalller, TotalBytes, TotalFreeBytes
    
    GetFreeSpace = TotalFreeBytes * 10000
    
End Function