VB获取磁盘已用与可用空间
来源:百度知道 编辑:UC知道 时间:2024/05/30 07:02:43
-----------------------------------------
下面给出判断磁盘空间的有关源码,供参考。
------------------------------------------
'From1内加入Drive1,Label1,Label2
和command1
'然后复制下面代码,运行即可
Option Explicit
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 Long
Private Sub Command1_Click()
End
End Sub
Private Sub Drive1_Change()
Dim Sectors As Long, Bytes As Long, Free As Long, Total As Long
Dim FreeKB As Long, TotalKB As Long
GetDiskFreeSpace Left(Drive1.Drive, 2) & "\", Sectors, Bytes, Free, Total
FreeKB = Bytes * Sectors * (Free \ 1024)
TotalKB = Bytes * Sectors * (Total \ 1024)
lblFree = FreeKB
lblTotal = TotalKB
End Sub
Priva