PDA

Click to See Complete Forum and Search --> : Extended GetDiskFreeSpace


CyberCarsten
Jan 13th, 2000, 02:37 AM
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

Aaron Young
Jan 13th, 2000, 02:48 AM
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.


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
aarony@redwingsoftware.com
ajyoung@pressenter.com

Ruchi
Jan 13th, 2000, 03:22 AM
Use GetDiskFreeSpaceEx API that is over 2 GB.


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


Label2.Caption = Format$( a * 10000, "###,###,###,###")


Hope this helps.

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

Juan Carlos Rey
Jan 15th, 2000, 09:35 AM
See this post:
http://www.vb-world.net/ubb/Forum1/HTML/011460.html

HTH!