Private 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
'Path = "c:\" 指定Volume 代號, 如: c:\ d:\ e:\
Public Function GetFreeSpace(Byval Path as String) as Long
Dim aa As Long
Dim Path As String
Dim SecPerClust As Long
Dim BytePerSec As Long, FreeClust As Long, totClust As Long
Path = "c:\" '指定Volume 代號, 如: c:\ d:\ e:\
aa = GetDiskFreeSpace(Path, SecPerClust, BytePerSec, FreeClust, totClust)
GetFreeSpace = SecPerClust * BytePerSec * FreeClust
End Function
'Path = "c:\" 指定Volume 代號, 如: c:\ d:\ e:\
Public Function GetTotalSpace(Byval Path as String) as Long
Dim aa As Long
Dim Path As String
Dim SecPerClust As Long
Dim BytePerSec As Long, FreeClust As Long, totClust As Long
aa = GetDiskFreeSpace(Path, SecPerClust, BytePerSec, FreeClust, totClust)
GetTotalSpace = SecPerClust * BytePerSec * totClust
End Function
但大於2GB的HardDisk需使用以下的API
Type ULARGE_INTEGER
LowPart As Long
HighPart As Long
End Type
Declare Function GetDiskFreeSpaceEx Lib "kernel32.dll" Alias "GetDiskFreeSpaceExA" _
(ByVal lpDirectoryName As String, _
lpFreeBytesAvailableToCaller As ULARGE_INTEGER, _
lpTotalNumberOfBytes As ULARGE_INTEGER, _
lpTotalNumberOfFreeBytes As ULARGE_INTEGER) As Long
參數順序:目錄名稱或磁碟機代碼 ,剩餘可用空間大小 (Bytes),
磁碟機總空間大小 (Bytes), 剩餘總空間大小 (Bytes)
|