GetDiskSpace (v4.00)

Share your advanced PureBasic knowledge/code with the community.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

GetDiskSpace (v4.00)

Post by PB »

Code updated For 5.20+


Prior to PureBasic v4.00 and its native support for Quads, this was done using
simulated quads and didn't return the value as bytes (it returned them as MB;
see viewtopic.php?t=3740 for example).

So here's my user-friendly contribution for v4.00! :)

Code: Select all

; GetDiskSpace procedure by PB (requires PureBasic v4.00).
;
; r=GetDiskSpace("c:","t") ; Get number of total bytes on C:
; r=GetDiskSpace("c:","f") ; Get number of free bytes on C:
; r=GetDiskSpace("c:","u") ; Get number of used bytes on C:
;
; r = -1 on failure (eg. drive not found, or bad type$ param).

Procedure.q GetDiskSpace(drive$,type$)
  value.q=-1
  If GetDiskFreeSpaceEx_(drive$,@free.q,@total.q,0)
    Select LCase(type$)
      Case "t" : value=total
      Case "f" : value=free
      Case "u" : value=total-free
      Default : value=-1
    EndSelect
  EndIf
  ProcedureReturn value
EndProcedure

Debug GetDiskSpace("c:","t")
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.