呼叫API函式得到磁碟上剩餘空間的值 (轉)

gugu99發表於2008-07-18
呼叫API函式得到磁碟上剩餘空間的值 (轉)[@more@]

 

 

得到上剩餘空間的值


最直接的方法是呼叫API函式 GetDiskFreeSpace,函式宣告如下:

宣告:

Declare Function GetDiskFreeSpace Lib "kernel32" Alias 
"GetDiskFreeSpaceA" (ByVal lpPathName As String, lpSectorsPerCluster 
As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, 
lpTtoalNumberOfClusters As Long) As Long


使用:

Private Sub Form_Load()
'Man 2001
'URL:
'E-: 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/10748419/viewspace-1007455/,如需轉載,請註明出處,否則將追究法律責任。

相關文章