Results 1 to 4 of 4

Thread: Extended GetDiskFreeSpace

  1. #1

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544

    Post

    I have made this program to calculate total amount of free space
    on a harddrive...BUT!!!
    It only goes to 2,147,155,968 bytes!!
    I know there is an extended version of the GetDiskFreeSpace...could
    anyone help??


    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

    Private Sub Drive1_Change()
    Dim x As Long
    Dim SperC As Long
    Dim BPerS As Long
    Dim NoFC As Long
    Dim TNoC As Long
    Dim BytesFree As Long
    Dim Root As String

    Root = Left(Drive1.Drive, 2) & "\"

    x& = GetDiskFreeSpace(Root, SperC&, BPerS, NoFC&, TNoC&)

    'Fill Labels
    Label1.Caption = Format(SperC& * BPerS * NoFC&, "0,000") & " bytes"
    Label2.Caption = Format(SperC& * BPerS * NoFC& / 1024000, "0.00") & " MB"

    End Sub

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    The Problem is with your Data Types in the Calculation, not the API, you're multiplying Long Values which have a Max Value of 2,147,483,647, you can use CDbl() to Tell VB to treat the Answer as a Double, giving you a range of upto 1.79769313486232E308, ie.

    Code:
    Label1.Caption = Format(CDbl(SperC&) * BPerS * NoFC&, "0,000") & " bytes"
    Label2.Caption = Format(CDbl(SperC&) * BPerS * NoFC& / 1024000, "0.00") & " MB"

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]


  3. #3
    Member
    Join Date
    Dec 1999
    Posts
    37

    Post

    Use GetDiskFreeSpaceEx API that is over 2 GB.

    Code:
    Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, 
    lpSectorsPerCluster As Long, lpBytesPerSector As Long, 
    lpNumberOfFreeClusters As Long, 
    lpTotalNumberOfClusters As Long) As Long
    a = the total of free bytes

    Code:
    Label2.Caption = Format$( a * 10000, "###,###,###,###")
    Hope this helps.

    [This message has been edited by Ruchi (edited 01-13-2000).]

  4. #4
    Hyperactive Member Juan Carlos Rey's Avatar
    Join Date
    Aug 1999
    Location
    Mendoza, Argentina
    Posts
    301

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width