Click to See Complete Forum and Search --> : Hard Drive Info
Master
Dec 4th, 1999, 06:57 AM
How do I get the amount of free space on a certain hard drive of a system?
Aaron Young
Dec 4th, 1999, 07:23 AM
Use the GetDiskFreeSpace API, eg.
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
aarony@redwingsoftware.com
adyoung@win.bright.net
[This message has been edited by Aaron Young (edited 12-04-1999).]
Serge
Dec 4th, 1999, 10:27 PM
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.
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
Example:
MsgBox "Free space on drive C: is: " & GetFreeSpace("C:")
------------------
Serge
Software Developer
Serge_Dymkov@vertexinc.com
Access8484@aol.com
ICQ#: 51055819 (http://www.icq.com/51055819)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.