VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Determine free disk space

by Anonymous (267 Submissions)
Category: Windows System Services
Compatability: Visual Basic 4.0 (32-bit)
Difficulty: Unknown Difficulty
Originally Published: Fri 18th December 1998
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Determine free disk space

Rate Determine free disk space



Dim lngSectorsPerCluster As Long
Dim lngBytesPerSector As Long
Dim lngNumberOfFreeClusters As Long
Dim lngTotalNumberOfClusters As Long

Dim strDrive As String
Dim strMessage As String
Dim lngTotalBytes As Long
Dim lngFreeBytes As Long

    strDrive = "C:\" 'drive letter
    
    If GetDiskFreeSpace(strDrive, lngSectorsPerCluster, lngBytesPerSector, lngNumberOfFreeClusters, lngTotalNumberOfClusters) = 0 Then
        strMessage = strMessage & vbCrLf & "An error occurred."
    Else
        strMessage = strMessage & vbCrLf & "Sectors Per Cluster: " & Format$(lngSectorsPerCluster)
        strMessage = strMessage & vbCrLf & "Bytes Per Sector: " & Format$(lngBytesPerSector)
        strMessage = strMessage & vbCrLf & "Free Clusters: " & Format$(lngNumberOfFreeClusters)
        strMessage = strMessage & vbCrLf & "Total Clusters: " & Format$(lngTotalNumberOfClusters)
        lngTotalBytes = lngTotalNumberOfClusters * lngSectorsPerCluster * lngBytesPerSector
        strMessage = strMessage & vbCrLf & "Total Bytes: " & Format$(lngTotalBytes)
        lngFreeBytes = lngNumberOfFreeClusters * lngSectorsPerCluster * lngBytesPerSector
        strMessage = strMessage & vbCrLf & "Bytes Free: " & Format$(lngFreeBytes)
        strMessage = strMessage & vbCrLf & "Percent Used: " & Format$(1 - (lngFreeBytes / lngTotalBytes), "0.00%")
    End If
    
    MsgBox (strMessage)

Download this snippet    Add to My Saved Code

Determine free disk space Comments

No comments have been posted about Determine free disk space. Why not be the first to post a comment about Determine free disk space.

Post your comment

Subject:
Message:
0/1000 characters