|   
 UID1 威望1240 点 金钱24019 金币 点卡317 点 
 | 
1#
 发表于 2002-10-27 02:11 
 | 只看该作者 
 如何求出硬盘大小及剩余空间大小
| 在我们安装软体的时候,在安装选项的画面,常常会出现如下的一些叙述: 选择安装项目大小..............................................10,000,000 Bytes
 C 硬盘总空间大小..........................................1,847,328,768 Bytes
 C 硬盘剩余空间大小...........................................51,707,904 Bytes
 后面的二项是我们硬盘的资讯,我们只要使用一个 API,就可以同时抓到这二个资讯!
 请在声明区中放入以下声明:
 Private Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTotalNumberOfClusters As Long) As Long
 '第一个参数是硬盘代号,其他参数如范例中说明
 '在程序中呼叫范例如下:
 Private Sub Command1_Click()
 Dim SectorsPerCluster As Long '参数二:每个 Cluster 的 Sector 数
 Dim BytesPerSector As Long '参数三:每个 Sector 的 Byte 数
 Dim NumberOfFreeClusters As Long '参数四:剩余的 Cluster 数
 Dim TotalNumberOfClusters As Long '参数五:Cluster 总数
 Dim FreeBytes As Long '剩余的 Byte 数
 Dim TotalBytes As Long '总 Byte 数
 Dim dummy As Long '传回值
 dummy = GetDiskFreeSpace("c:\", SectorsPerCluster, BytesPerSector, NumberOfFreeClusters, TotalNumberOfClusters)
 FreeBytes = NumberOfFreeClusters * SectorsPerCluster * BytesPerSector
 TotalBytes = TotalNumberOfClusters * SectorsPerCluster * BytesPerSector
 剩余空间大小 = FreeBytes
 硬盘大小 = TotalBytes
 End Sub
 注:在 VB6 以前的各版本 VB,只能使用这种方法来做,但是到了 VB6 已经有了更简单、不要使用 API 的新作法,就是使用新物件 FileSystemObject.
 
 
 
 | 
 
| 我是一个呼吸着现在的空气而生活在过去的人
 这样的注定孤独,孤独的身处闹市却犹如置身于荒漠
 我已习惯了孤独,爱上孤独
 他让我看清了自我,还原了自我
 让我再静静的沉思中得到快乐和满足
 再孤独的世界里我一遍又一遍
 不厌其烦的改写着自己的过去
 延伸到现在与未来
 然而那只是泡沫般的美梦
 产生的时刻又伴随着破灭的到来
 在灰飞烟灭的瞬间我看到的是过程的美丽
 而不是结果的悲哀。。。
 
 |  |