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

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 shawls 的 blog

 

 

调用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) *剩余扇区 *每扇区的字节数

本文关键:vb,API,磁盘,空间
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top