Results 1 to 3 of 3

Thread: GetDiskFreeSpace

  1. #1
    mik706
    Guest

    GetDiskFreeSpace

    I am trying to determine the amount of free space on a disk but am losing the plot.
    i am trying to use the GetDiskFreeSpace API but to no availe. Could someone please show me how to use this API or suggest a better approch.

  2. #2
    Junior Member
    Join Date
    Mar 2001
    Posts
    18

    Here is the answer from Dan Appleman.

    Taken from:
    Dan Appleman
    Visual Basic Programmer's Guide to the Win32 API
    The Authoritative Solution

    A great book for any person who uses this usefull api.

    Only problem I was getting is an overflow:

    TotalBytes = TotalNumberOfClustors * SectorsPerCluster * BytesPerSector

    Too many bytes even on a 4 gig drive.
    You may want to make it a string and work with it that way?

    -Xiquon
    Attached Files Attached Files

  3. #3
    Matthew Gates
    Guest
    Try this:


    VB Code:
    1. Private Declare Function GetDiskFreeSpaceEx _
    2. Lib "kernel32" Alias "GetDiskFreeSpaceExA" (Byval _
    3. lpRootPathName As String, lpFreeBytesAvailableToCaller _
    4. As Currency, lpTotalNumberOfBytes As Currency, _
    5. lpTotalNumberOfFreeBytes As Currency) As Long
    6.  
    7. Private Sub Form_Load()
    8.     Dim r As Long, BytesFreeToCalller As Currency, TotalBytes As Currency
    9.     Dim TotalFreeBytes As Currency, TotalBytesUsed As Currency
    10.     'the drive to find
    11.     Const RootPathName = "C:\"
    12.     'get the drive's disk parameters
    13.     Call GetDiskFreeSpaceEx(RootPathName, BytesFreeToCalller, TotalBytes, TotalFreeBytes)
    14.     'show the results, multiplying the returned
    15.     'value by 10000 to adjust for the 4 decimal
    16.     'places that the currency data type returns.
    17.     Me.AutoRedraw = True
    18.     Me.Cls
    19.     Me.Print
    20.     Me.Print " Total Number Of Bytes:", Format$(TotalBytes * 10000, "###,###,###,##0") & " bytes"
    21.     Me.Print " Total Free Bytes:", Format$(TotalFreeBytes * 10000, "###,###,###,##0") & " bytes"
    22.     Me.Print " Free Bytes Available:", Format$(BytesFreeToCalller * 10000, "###,###,###,##0") & " bytes"
    23.     Me.Print " Total Space Used :", Format$((TotalBytes - TotalFreeBytes) * 10000, "###,###,###,##0") & " bytes"
    24. 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
  •  



Click Here to Expand Forum to Full Width