GetFreeDiscSpace

Share your advanced PureBasic knowledge/code with the community.
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

GetFreeDiscSpace

Post by GPI »

Code updated for 5.20+

Code: Select all

Procedure.s GetFreeSpace(drive.s)
  If GetDiskFreeSpaceEx_(@drive, @FB.q, @TB.q, @TFB.q)
    Define f.f, freeSpace.s
    If TFB => 1099511627776
      f = TFB / 1099511627776
      freeSpace = StrF(f, 3) + " TB"
    ElseIf TFB => 1073741824
      f = TFB / 1073741824
      freeSpace = StrF(f, 3) + " GB"
    ElseIf TFB => 1048576
      f = TFB / 1048576
      freeSpace = StrF(f, 3) + " MB"
    ElseIf TFB => 1024
      f = TFB / 1024
      freeSpace = StrF(f, 3) + " KB"
    Else
      freeSpace = StrF(TFB, 3) + " bytes"
    EndIf
  EndIf
  ProcedureReturn freeSpace
EndProcedure

Debug GetFreeSpace("c:\")
User avatar
blueb
Addict
Addict
Posts: 1121
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Post by blueb »

Very nice GPI..... thanks 8)

I had to rename it to: GetFreeDriveSpace(p$) because GetFreeSpace already exists in WinAPI.

--blueb
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

Thx for sharing, but hey it isnt acurate! :S
TronDoc
Enthusiast
Enthusiast
Posts: 310
Joined: Wed Apr 30, 2003 3:50 am
Location: 3DoorsDown

Post by TronDoc »

for windows only :?:
Linux:
Line 24: GetDiskFreeSpaceEx_() is not a function, an array, or a linked list
peace
[pI 166Mhz 32Mb w95]
[pII 350Mhz 256Mb atir3RagePro WinDoze '98 FE & 2k]
[Athlon 1.3Ghz 160Mb XPHome & RedHat9]
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2148
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Post by Andre »

TronDoc wrote:for windows only :?:
Linux:
Line 24: GetDiskFreeSpaceEx_() is not a function, an array, or a linked list
Its a function from the Windows API, so you are right.
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
User avatar
blueb
Addict
Addict
Posts: 1121
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Post by blueb »

Dagcrack - Thx for sharing, but hey it isnt acurate!
dagcrack,

Reloaded and checked. Accurate :)

Using WinXP Pro

blueb
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

No, shows less than I really have.
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post by GPI »

dagcrack wrote:No, shows less than I really have.
What exact is shown and what do you really have.

Maybe a round-error. btw: Funny: Some Windows-Windows show, that a file has 26 KB, other that the file has 25 KB...
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

I trust in TC 8)
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post by GPI »

dagcrack wrote:I trust in TC 8)
?!
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

Oouoh... TC = TotalCommander
Post Reply