Declare Function GetDiskFreeSpace Lib "Kernel32" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTtoalNumberOfClusters As Long) As Long
Function GetDiskSpaceFree(ByVal strDrive As String) As Long
Const strSEP_DRIVE$ = ":"
Dim strCurDrive As String
Dim lDiskFree As Long
On Error Resume Next
strCurDrive = Left$(CurDir$, 2)
If InStr(strDrive, strSEP_DRIVE) = 0 Or Len(strDrive) > 2 Then
strDrive = Left$(strDrive, 1) & strSEP_DRIVE
End If
ChDrive strDrive
If Err <> 0 Then
lDiskFree = -1
Else
Dim lRet As Long
Dim lBytes As Long, lSect As Long, lClust As Long, lTot As Long
lRet = GetDiskFreeSpace(vbNullString, lSect, lBytes, lClust, lTot)
On Error Resume Next
lDiskFree = (lBytes * lSect) * lClust
If Err Then lDiskFree = 2147483647
End If
If lDiskFree = -1 Then
MsgBox Error$ & vbLf & _
"确定驱动器 " & strDrive & " 的磁盘可用空间时出错", _
vbExclamation, "Error"
End If
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 d As String
Dim SecpC As Long
Dim BpS As Long
Dim fC As Long
Dim tC As Long
Dim f As Double
GetDiskFreeSpace "d:", SecpC, BpS, fC, tC
f = CDbl(SecpC) * CDbl(BpS) * CDbl(fC)
d = "D盘剩余:" & f & " Byte"
Debug.Print SecpC, BpS, fC, tC, d