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