GetDiskFreeSpaceEx 函数

本文介绍了一种使用VB编程语言来获取指定磁盘分区的总容量、可用空间及已使用空间的方法。通过调用Windows API函数GetDiskFreeSpaceEx,实现了磁盘空间信息的实时监测。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

已解决问题

VB如何得到一个文件占用磁盘空间的大小
30  [ 标签:vb磁盘空间大小 ]  易凌风  2010-02-12 23:26
如题
满意答案 好评率:100%
20100212222710-240208820.jpg
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

本文转自 bilinyee博客,原文链接:      http://blog.51cto.com/215363/955731   如需转载请自行联系原作者      

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值