GetDiskFreeSpaceEx 函数

已解决问题

收藏 转载到空间 转播到腾讯微博

VB如何得到一个文件占用磁盘空间的大小

30 [ 标签:vb, 磁盘空间, 大小 ] 易凌风 2010-02-12 23:26
如题

满意答案 好评率:100%

Option Explicit
Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" _
Alias "GetDiskFreeSpaceExA" _
(ByVal lpRootPathName As String, _
lpFreeBytesAvailableToCaller As Currency, _
lpTotalNumberOfBytes As Currency, _
lpTotalNumberOfFreeBytes As Currency) As Long
Dim r As Long
Dim BytesFreeToCalller As Currency
Dim TotalBytes As Currency
Dim TotalFreeBytes As Currency
Dim TotalBytesUsed As Currency
Dim RootPathName As String
Dim DiskName As String

Private Sub exit_Click()
Unload Me
End Sub
Private Sub Form_Load()
Timer1.Interval = 100 '每0.1秒发生一次Timer事件
Drive1.Drive = "c:"
checkdiskform.Left = (Screen.Width - checkdiskform.Width) / 2
checkdiskform.Top = (Screen.Height - checkdiskform.Height) / 2
End Sub
Private Sub Timer1_Timer()
RootPathName = Drive1.Drive
RootPathName = Mid(RootPathName, 1, 2)
DiskName = StrConv(Left(RootPathName, 1), vbUpperCase)
On Error GoTo errhandler
Dir1.Path = Drive1.Drive
Dim x As String
Label1 = DiskName + "盘的容量信息"
'调用API函数获取容量信息
r = GetDiskFreeSpaceEx(RootPathName, BytesFreeToCalller, TotalBytes, TotalFreeBytes)
'用FORMAT函数输出习惯的数据 显示格式
total.Text = Format$(TotalBytes * 10000, "###,###,###,##0")
free.Text = Format$(TotalFreeBytes * 10000, "###,###,###,##0")
used.Text = Format$((TotalBytes - TotalFreeBytes) * 10000, "###,###,###,##0")
Exit Sub

你可能感兴趣的:(收藏)