Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleDisplay a warning when a disk is too full
Keywordsfull, disk, warning
CategoriesUtilities
 
When a Timer fires, check the disk's free space. Present a warning if it has dropped below a desired limit.

Thanks to Evi Hairani

 
Private Declare Function GetDiskFreeSpace Lib "kernel32" _
    Alias "GetDiskFreeSpaceA" _
  (ByVal lpRootPathName As String, _
   lpSectorsPerCluster As Long, _
   lpBytesPerSector As Long, _
   lpNumberOfFreeClusters As Long, _
   lpTotalNumberOfClusters As Long) As Long

' Get the free space.
Private Sub GetFreeSpace(ByVal drive_letter As String, _
    ByRef total_size As Double, ByRef total_free As Double)

    If GetDiskFreeSpace(drive_letter & ":\", _
        sectors_per_cluster, _
        bytes_per_sector, _
        num_free_clusters, _
        total_clusters) _
    Then
        total_size = total_clusters * sectors_per_cluster * _
            bytes_per_sector
        total_free = num_free_clusters * _
            sectors_per_cluster * bytes_per_sector
    Else
        total_size = 0
        total_free = 0
    End If
End Sub

Private Sub Form_Load()
  cbdrive.ListIndex = 0
End Sub

Private Sub Timer1_Timer()
Dim TotSize As Double
Dim TotFree As Double

' do something
  GetFreeSpace cbdrive.Text, TotSize, TotFree
  If (TotFree / 1024) / 1024 < CLng(Txtsize) Then
    frmTip.Show
  End If
End Sub
 
Formatted by Neil Crosby
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated