COUNTING DISK SPACE


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: COUNTING DISK SPACE

  1. #1
    James Guest

    COUNTING DISK SPACE


    I have tried to get the code used in some VISUAL BASIC6
    on how to get the Free DIsk Space, but could not succeed.
    Please Help
    Thanks in advance

  2. #2
    Jim Gotwald Guest

    Re: COUNTING DISK SPACE


    "James" <James@hotmail.Com> wrote:
    >
    >I have tried to get the code used in some VISUAL BASIC6
    > on how to get the Free DIsk Space, but could not succeed.
    > Please Help
    > Thanks in advance

    Try This:


    ' GetDiskFreeSpaceEx uses a data type that VB6 doesn't know about -
    ' LARGE_INTEGER which is basically an 8 byte unsigned integer,
    ' so we've got to set up a user-defined type that can hold that much
    '
    Private Type LargeInt
    LoByte As Byte
    Byte2 As Byte
    Byte3 As Byte
    Byte4 As Byte
    Byte5 As Byte
    Byte6 As Byte
    Byte7 As Byte
    HiByte As Byte
    End Type

    ' Now Declare the API function...
    Private Declare Function GetDiskFreeSpaceEx _
    Lib "kernel32" _
    Alias "GetDiskFreeSpaceExA" ( _
    ByVal lpRootPathName As String, _
    ByRef lpFreeBytesAvailableToCaller As Any, _
    ByRef lpTotalNumberOfBytes As Any, _
    ByRef lpTotalNumberOfFreeBytes As Any) As Long

    Dim li As LargeInt

    Private Function LIValue(li As LargeInt) As Double
    ' This function converts the LARGE_INTEGER value into a
    ' single (which is BIG enough to hold an unsigned 64 bit value without scientific
    notation)
    LIValue = ((((((CSng(li.HiByte) * 256 + _
    CSng(li.Byte7)) * 256 + _
    CSng(li.Byte6)) * 256 + _
    CSng(li.Byte5)) * 256 + _
    CSng(li.Byte4)) * 256 + _
    CSng(li.Byte3)) * 256 + _
    CSng(li.Byte2)) * 256 + _
    CSng(li.LoByte)
    End Function

    Private Sub Form_Load()
    Dim Success As Long
    Dim BytesAvailable As LargeInt
    Dim TotalBytes As LargeInt
    Dim FreeBytes As LargeInt

    Success = GetDiskFreeSpaceEx("C:\", BytesAvailable, TotalBytes, FreeBytes)
    If Success <> 0 Then
    Debug.Print "Drive C: has " & Format(LIValue(FreeBytes), "#,###"); "
    free on a " & Format(LIValue(TotalBytes), "#,###") & " byte drive. (" &
    Format(LIValue(BytesAvailable), "#,###") & " available.)"
    End If
    End Sub


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center