CodeItBetter Programming Another VB Programming Blog

How to Find the Disk Capacity, Free and Used space

Posted on January 5, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
'File/Folder Handling - How to Find the Disk Capacity, Free and Used space

Option Explicit
 
Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" _
    (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, _
    lpNumberOfFreeClusters As Long, lpTtoalNumberOfClusters As Long) As Long
 
Private Sub Main()
    Dim lSectorsPerCluster As Long, lBytesPerSector As Long, lNumberOfFreeClusters As Long
    Dim lTtoalNumberOfClusters As Long, lResult As Long
    Dim lCapacity As Long, lFreeSpace As Long, lUsedSpace As Long
    lResult = GetDiskFreeSpace("C:\", lSectorsPerCluster, lBytesPerSector, lNumberOfFreeClusters, lTtoalNumberOfClusters)
    If Not lResult = 0 Then
        lCapacity = lSectorsPerCluster * lBytesPerSector * lTtoalNumberOfClusters
        lFreeSpace = lSectorsPerCluster * lBytesPerSector * lNumberOfFreeClusters
        lUsedSpace = lCapacity - lFreeSpace
        MsgBox "Capacity: " & lCapacity & " Bytes" & vbCrLf & _
               "Free:     " & lFreeSpace & " Bytes" & vbCrLf & _
               "Used:     " & lUsedSpace & " Bytes"
    End If
End Sub
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.