新建From1(窗体),新建Command1(按钮CommandButton),代码:
Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias "GetDiskFreeSpaceExA" (ByVal lpRootPathName As String, lpFreeBytesAvailableToCaller As Currency, lpTotalNumberOfBytes As Currency, lpTotalNumberOfFreeBytes As Currency) As Long
Function DriveFreeSpace(sDriveLetter As String) As Double
Dim lRet As Long, cBytesFree As Currency, cTotalBytes As Currency, cTotalBytesFree As Currency
On Error Resume Next
If GetDiskFreeSpaceEx(Left$(sDriveLetter, 1) & ":\", cBytesFree, cTotalBytes, cTotalBytesFree) <> 0 Then
DriveFreeSpace = (cTotalBytes - cBytesFree) * 10000
End If
On Error GoTo 0
End Function
Private Sub Command1_Click()
MsgBox DriveFreeSpace("c")
End Sub