How do I get the amount of free space on a certain hard drive of a system?
Printable View
How do I get the amount of free space on a certain hard drive of a system?
Use the GetDiskFreeSpace API, eg.
------------------Code: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
Private Sub Command1_Click()
Dim lSPC As Long, lBPS As Long, lNFC As Long, lTNC As Long
Call GetDiskFreeSpace(ByVal "C:\", lSPC, lBPS, lNFC, lTNC)
Caption = Format(CCur(lSPC * lBPS * lNFC), "##,##")
End Sub
Aaron Young
Analyst Programmer
[email protected]
[email protected]
[This message has been edited by Aaron Young (edited 12-04-1999).]
Aaron is right but GetDiskFreeSpace API can handle hard drives up to 2GB. To get the free space for hard drives over 2GB use GetDiskFreeSpaceEx instead.
Example:Code:Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias "GetDiskFreeSpaceExA" (ByVal lpRootPathName As String, lpFreeBytesAvailableToCaller As Currency, lpTotalNumberOfBytes As Currency, lpTotalNumberOfFreeBytes As Currency) As Long
Private Function GetFreeSpace(pDrive As String) As String
Dim curTotalBytes As Currency
Dim curFreeBytesToCaller As Currency
Dim curTotalFreeBytes As Currency
Call GetDiskFreeSpaceEx(pDrive, curFreeBytesToCaller, curTotalBytes, curTotalFreeBytes)
GetFreeSpace = Format$(curTotalFreeBytes * 10000, "###,###,###,##0")
End Function
MsgBox "Free space on drive C: is: " & GetFreeSpace("C:")
------------------
Serge
Software Developer
[email protected]
[email protected]
ICQ#: 51055819