# Re: 如何得知磁碟剩余空间

Posted by 陈凯程 on February 08, 1998 at 04:41:29:

In Reply to: 如何得知磁碟剩余空间 posted by VB菜鸟 on February 08, 1998 at 02:43:33:

: 各位VB高手:

: 要如何才能得知硬碟及软碟的剩余空间 ,希望不吝赐教 !

用以下的程式码吧！

Private Declare Function DISKSPACEFREE Lib "stkit432.DLL" () As Long

Public Function DiskSpace(DriveName As String) As Long
Dim CurrentDir As String
Dim StartDrive As String
StartDrive = Left(CurDir$, 2)
On Error GoTo CheckDiskError
CurrentDir = Dir$(DriveName + "\*.*")
ChDrive DriveName
DiskSpace = DISKSPACEFREE()
On Error GoTo 0
ChDrive DriveName
Exit Function
CheckDiskError:
DiskSpace = -Err
On Error GoTo 0
Err = 0
Exit Function
End Function

希望能帮到您，若有错误的话，请多多指教！

Follow Ups: