Page 1 of 1

GetDiskSpace (v4.00)

Posted: Sun Feb 26, 2006 10:43 pm
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")