October 2009
M T W T F S S
    Nov »
 1234
567891011
12131415161718
19202122232425
262728293031  

Archives

Categories

  • [+]ASP.NET (7) 
  • [+]C# (87) 
  • [+]C++ (13) 
  • [+]Delphi (20) 
  • [+]JavaScript (24) 
  • [+]Regular Expressions (7) 
  • [+]SQL (13) 
  • [—]VB (100) 
  • [+]VB.NET (4) 

Online

Users: 7 Guests, 1 Bot
  • Loading...


    Loading...

    Login






    Register | Lost password?

    Register





    A password will be mailed to you.
    Log in | Lost password?

    Retrieve password





    A confirmation mail will be sent to your e-mail address.
    Log in | Register
  • Get the amount of free disk space for the specified drive

    '-----------------------------------------------------------
    ' FUNCTION: GetDiskSpaceFree
    ' Get the amount of free disk space for the specified drive
    '
    ' IN: [strDrive] - drive to check space for
    '
    ' Returns: Amount of free disk space, or -1 if an error occurs
    '-----------------------------------------------------------
    '
    Function GetDiskSpaceFree(ByVal strDrive As String) As Long
        Dim strCurDrive As String
        Dim lDiskFree As Long
    
        On Error Resume Next
    
        '
        'Save the current drive
        '
        strCurDrive = Left$(CurDir$, 2)
    
        '
        'Fixup drive so it includes only a drive letter and a colon
        '
        If InStr(strDrive, gstrSEP_DRIVE) = 0 Or Len(strDrive) > 2 Then
            strDrive = Left$(strDrive, 1) & gstrSEP_DRIVE
        End If
    
        '
        'Change to the drive we want to check space for.  The DiskSpaceFree() API
        'works on the current drive only.
        '
        ChDrive strDrive
    
        '
        'If we couldn't change to the request drive, it's an error, otherwise return
        'the amount of disk space free
        '
        If Err <> 0 Or (strDrive <> Left$(CurDir$, 2)) Then
            lDiskFree = -1
        Else
            Dim lRet As Long
            Dim lBytes As Long, lSect As Long, lClust As Long, lTot As Long
    
            lRet = GetDiskFreeSpace(vbNullString, lSect, lBytes, lClust, lTot)
            On Error Resume Next
            lDiskFree = (lBytes * lSect) * lClust
            If Err Then lDiskFree = 2147483647
        End If
    
        If lDiskFree = -1 Then
            MsgError Error$ & vbLf & vbLf & ResolveResString(resDISKSPCERR) & strDrive, vbExclamation, gstrTitle
        End If
    
        GetDiskSpaceFree = lDiskFree
    
        '
        'Cleanup by setting the current drive back to the original
        '
        ChDrive strCurDrive
    
        Err = 0
    End Function
    
    Share: These icons link to social bookmarking sites where readers can share and discover new web pages.
    • Digg
    • del.icio.us
    • Bloglines
    • Facebook
    • Google Bookmarks
    • LinkedIn
    • Technorati
    • TwitThis
    • Webnews

    Leave a Reply

     

     

     

    You can use these HTML tags

    <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <font color="" face="" size=""> <span style="">

    Spam Protection by WP-SpamFree Plugin