|
-
Dec 4th, 1999, 07:57 AM
#1
Thread Starter
Member
How do I get the amount of free space on a certain hard drive of a system?
-
Dec 4th, 1999, 08:23 AM
#2
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).]
-
Dec 4th, 1999, 11:27 PM
#3
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.
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
Example:
MsgBox "Free space on drive C: is: " & GetFreeSpace("C:")
------------------
Serge
Software Developer
[email protected]
[email protected]
ICQ#: 51055819
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|