|
-
Mar 30th, 2000, 07:00 PM
#1
Thread Starter
Addicted Member
Put a Drive List Box (Drive 1) at the top of a Form, make the Form about 5" wide by about 5" High and add the following code to the Form:
Code:
Option Explicit
Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" _
Alias "GetDiskFreeSpaceExA" _
(ByVal lpRootPathName As String, _
lpFreeBytesAvailableToCaller As Currency, _
lpTotalNumberOfBytes As Currency, _
lpTotalNumberOfFreeBytes As Currency) As Long
Dim r As Long, BytesFreeToCalller As Currency, TotalBytes As Currency
Dim TotalFreeBytes As Currency, TotalBytesUsed As Currency
Dim TNB As Double
Dim TFB As Double
Dim FreeBytes As Long
Dim DriveLetter As String
Dim DLetter As String
Dim spaceInt As Integer
Public Sub GetDiskInfo()
'The following code prepares the drive letter. It is
'essential that you pass the drive letter to the API
'function in the form c:\. You can not pass
'Drive1.Drive directly because often this does not
'contain the correct format ("c:\").
'copy the drive letter into the variable DriveLetter
DriveLetter = Drive1.Drive
'If there is a space on the end of DriveLetter, remove it
spaceInt = InStr(DriveLetter, " ")
If spaceInt > 0 Then DriveLetter = Left$(DriveLetter, spaceInt - 1)
'if there is not a "\" on the end of DriveLetter, add it
If Right$(DriveLetter, 1) <> "\" Then DriveLetter = DriveLetter & "\"
DLetter = Left(UCase(DriveLetter), 1)
'get the drive's disk parameters
Call GetDiskFreeSpaceEx(DriveLetter, BytesFreeToCalller, TotalBytes, TotalFreeBytes)
'show the results, multiplying the returned
'value by 10000 to adjust for the 4 decimal
'places that the currency data type returns.
AutoRedraw = True
Cls
ForeColor = QBColor(1)
Print
Print
Print
Print
Print " Information for Drive " & DLetter
Print " ------------------------------------ "
Print
Print " Total Number Of Bytes:", Format$(TotalBytes * 10000, "###,###,###,##0") & " bytes"
Print " Total Free Bytes:", Format$(TotalFreeBytes * 10000, "###,###,###,##0") & " bytes"
Print " Free Bytes Available:", Format$(BytesFreeToCalller * 10000, "###,###,###,##0") & " bytes"
Print " Total Space Used :", Format$((TotalBytes - TotalFreeBytes) * 10000, "###,###,###,##0") & " bytes"
Print
ForeColor = QBColor(12)
TNB = TotalBytes * 10000
TFB = (TotalBytes - TotalFreeBytes) * 10000
Print " % - Drive " & DLetter & ": Disk Space Used = " & Format(TFB / TNB * 100, "###.#0") & " %"
Print " % - Drive " & DLetter & ": Disk Space Available = " & Format(100 - TFB / TNB * 100, "###.#0") & " %"
Print
End Sub
Private Sub Drive1_Change()
GetDiskInfo
End Sub
Private Sub Form_Load()
GetDiskInfo
End Sub
-
Mar 30th, 2000, 07:06 PM
#2
Fanatic Member
Thank you, johnpc.
Thanks for the help!
r0ach™
Don't forget to rate the post
-
Mar 31st, 2000, 07:17 AM
#3
Fanatic Member
Hi,
Maybe this is a stupid question, but i need to know how to determine the total disk space, and either the used or free space on that disk. Can anyone help?
r0ach™
Don't forget to rate the post
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|