computer 版 (精华区)

发信人: windoe (为中国电信做贡献), 信区: program
标  题: VB:如何用程序获得磁盘的剩余空间?
发信站: 听涛站 (Fri Mar 10 19:09:17 2000), 转信

使用Windows 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
'获得磁盘剩余空间的函数
Public Function DiskSpace(DrivePath As String) As Double
Dim Drive As String
Dim SectorsPerCluster As Long, BytesPerSector As Long
Dim NumberOfFreeClusters As Long, TotalClusters As Long, Sts As Long
Dim DS
Drive = Left(Trim(DrivePath), 1) & ":\"
Sts = GetDiskFreeSpace(Drive, SectorsPerCluster, BytesPerSector,
NumberOfFreeClusters, TotalClusters)
If Sts <> 0 Then
DiskSpace = SectorsPerCluster * BytesPerSector
* NumberOfFreeClusters
Else
DiskSpace = -1
End If
End Function


--By Kammi's SuperPost General Version
--

夜中不能寐,起坐弹鸣琴。
    薄帷鉴明月,清风吹我襟。
孤鸿号外野,翔鸟鸣北林。
    徘徊将何见,忧思独伤心。


[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:0.657毫秒