'In general section Private Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTtoalNumberOfClusters As Long) As LongPrivate Sub Form_Load() 'KPD-Team 1998 'URL: http://www.allapi.net/ 'E-Mail: [email protected] Dim Sectors As Long, Bytes As Long, FreeC As Long, TotalC As Long, Total As Long, Freeb As Long 'Retrieve information about the C: GetDiskFreeSpace "C:\", Sectors, Bytes, FreeC, TotalC 'Set graphic mode to persistent Me.AutoRedraw = True 'Print the information to the form Me.Print " Path: C:\" Me.Print " Sectors per Cluster:" + Str$(Sector) Me.Print " Bytes per sector:" + Str$(Bytes) Me.Print " Number Of Free Clusters:" + Str$(FreeC) Me.Print " Total Number Of Clusters:" + Str$(TotalC) Total = rTotalc& * rSector& * rBytes& Me.Print " Total number of bytes in path:" + Str$(Total) Freeb = rFreec& * rSector& * rBytes& Me.Print " Free bytes:" + Str$(Freeb) End Sub
http://www.vczx.com/article/show.php?id=544
够快,刚想打个GetDiskSpace()出来,就回了两句QQ就被你们把分抢走了!
用FSO 很容易实现: Option Explicit '需要引用 Microsoft Scripting RuntimePrivate Sub Command1_Click() Dim mDrive As Drive Dim FSO As New FileSystemObject Set mDrive = FSO.GetDrive("c:\") MsgBox mDrive.TotalSize Set FSO = Nothing Set mDrive = Nothing End Sub
Private Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTtoalNumberOfClusters As Long) As LongPrivate Sub Form_Load()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: [email protected] Dim Sectors As Long, Bytes As Long, FreeC As Long, TotalC As Long, Total As Long, Freeb As Long
'Retrieve information about the C: GetDiskFreeSpace "C:\", Sectors, Bytes, FreeC, TotalC
'Set graphic mode to persistent
Me.AutoRedraw = True
'Print the information to the form
Me.Print " Path: C:\"
Me.Print " Sectors per Cluster:" + Str$(Sector)
Me.Print " Bytes per sector:" + Str$(Bytes)
Me.Print " Number Of Free Clusters:" + Str$(FreeC)
Me.Print " Total Number Of Clusters:" + Str$(TotalC)
Total = rTotalc& * rSector& * rBytes&
Me.Print " Total number of bytes in path:" + Str$(Total)
Freeb = rFreec& * rSector& * rBytes&
Me.Print " Free bytes:" + Str$(Freeb)
End Sub
Option Explicit
'需要引用 Microsoft Scripting RuntimePrivate Sub Command1_Click()
Dim mDrive As Drive
Dim FSO As New FileSystemObject
Set mDrive = FSO.GetDrive("c:\")
MsgBox mDrive.TotalSize
Set FSO = Nothing
Set mDrive = Nothing
End Sub