VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Finds all Drives Free Space and Capacity. Regardless of size. Find Harddrive space, get drive space

by Xaero (2 Submissions)
Category: Windows API Call/Explanation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Fri 23rd March 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Finds all Drives Free Space and Capacity. Regardless of size. Find Harddrive space, get drive space, find space, get free space, find free

API Declarations


'This will find the hard-drive space of any drive, regardless of its size.
'Now, add three text boxes, then name them both 'Text1' and 'Text2' and 'Text3'
'Then add a Command Button and name it 'Command1'
'Then add the code beneath into the Form:

Rate Finds all Drives Free Space and Capacity. Regardless of size. Find Harddrive space, get drive space



    Alias "GetDiskFreeSpaceExA" (ByVal lpDirectoryName As String, _
    lpFreeBytesAvailableToCaller As Currency, _
    lpTotalNumberOfBytes As Currency, _
    lpTotalNumberOfFreeBytes As Currency) As Long
    Dim Status As Long
    Dim TotalBytes, TempTotalBytes As Currency
    Dim FreeBytes, TempFreeBytes As Currency
    Dim BytesAvailableToCaller As Currency
    Dim TotalSpaceValue, FreeSpaceValue As String
 Public Sub CalculateValues()
TempTotalBytes = 0
TempFreeBytes = 0
TotalBytes = 0
FreeBytes = 0
On Error Resume Next
Status = GetDiskFreeSpaceEx(Text1.Text, BytesAvailableToCaller, TotalBytes, FreeBytes)
If FreeBytes = 0 Then FreeSpaceValue = "Bytes"
If FreeBytes = 0 Then GoTo Confirm
If (FreeBytes * 10000 / 1024) < 1 Then GoTo FreeBytes_Bytes
If (FreeBytes * 10000 / 1024 / 1024) < 1 Then GoTo FreeBytes_Kilo
If (FreeBytes * 10000 / 1024 / 1024 / 1024) < 1 Then GoTo FreeBytes_Mega Else GoTo Giga
Exit Sub
FreeBytes_Bytes:
FreeSpaceValue = "Bytes"
TempFreeBytes = FreeBytes * 10000
GoTo Confirm
FreeBytes_Kilo:
FreeSpaceValue = "Kilobytes"
TempFreeBytes = FreeBytes * 10000 / 1024
GoTo Confirm
FreeBytes_Mega:
FreeSpaceValue = "Megabytes"
TempFreeBytes = FreeBytes * 10000 / 1024 / 1024
GoTo Confirm
Giga:
FreeSpaceValue = "Gigabytes"
TempFreeBytes = FreeBytes * 10000 / 1024 / 1024 / 1024
Confirm:
If (TotalBytes * 10000 / 1024) < 1 Then GoTo TotalBytes_Bytes
If (TotalBytes * 10000 / 1024 / 1024) < 1 Then GoTo TotalBytes_Kilo
If (TotalBytes * 10000 / 1024 / 1024 / 1024) < 1 Then GoTo TotalBytes_Mega Else GoTo TotalGiga
TotalBytes_Bytes:
TotalSpaceValue = "Bytes"
TempTotalBytes = TotalBytes * 10000
GoTo ReConfirm
TotalBytes_Kilo:
TotalSpaceValue = "Kilobytes"
TempTotalBytes = TotalBytes * 10000 / 1024
GoTo ReConfirm
TotalBytes_Mega:
TotalSpaceValue = "Megabytes"
TempTotalBytes = TotalBytes * 10000 / 1024 / 1024
GoTo ReConfirm
TotalGiga:
TotalSpaceValue = "Gigabytes"
TempTotalBytes = TotalBytes * 10000 / 1024 / 1024 / 1024
ReConfirm:
cstart = InStr(TempTotalBytes, ".")
TempTotalBytes = Left(TempTotalBytes, cstart - 1) & "." & Mid(TempTotalBytes, cstart + 1, 2)
cstart = InStr(TempFreeBytes, ".")
TempFreeBytes = Left(TempFreeBytes, cstart - 1) & "." & Mid(TempFreeBytes, cstart + 1, 2)
Text2.Text = "Drive Capacity: " & TempTotalBytes & " " & TotalSpaceValue
Text3.Text = "Free Space: " & TempFreeBytes & " " & FreeSpaceValue
End Sub

Private Sub Command1_Click()
CalculateValues
End Sub


Download this snippet    Add to My Saved Code

Finds all Drives Free Space and Capacity. Regardless of size. Find Harddrive space, get drive space Comments

No comments have been posted about Finds all Drives Free Space and Capacity. Regardless of size. Find Harddrive space, get drive space. Why not be the first to post a comment about Finds all Drives Free Space and Capacity. Regardless of size. Find Harddrive space, get drive space.

Post your comment

Subject:
Message:
0/1000 characters