调用API函数得到磁盘上剩余空间的值 (转)

调用API函数得到磁盘上剩余空间的值 (转)[@more@]

 

 

调用api函数得到磁盘上剩余空间的值


最直接的方法是调用API函数 GetDiskFreeSpace,函数声明如下:

声明:

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 Form_Load()
'vb Man 2001
'URL: http://goodvbman.yeah.NET
'E-Mail: coolde@21cn.com

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

计算规则:磁盘上剩余空间(字节)=磁道(Sector) *剩余扇区 *每扇区的字节数


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752043/viewspace-990118/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10752043/viewspace-990118/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值