free memory on sd card

Cor

Active Member
Licensed User
Longtime User
How to get the free memory on sd card.

Before i download a file i want to detect if there is enough room on sd card?

search forum but could not find
 
Thanks

the following code returns a list of available memory in device

Code:
    Dim p As Phone
    Dim sb As StringBuilder
    sb.Initialize
   p.Shell("df", Null, sb, Null)  ' free space
    Msgbox(sb.ToString, "Memory:")
 
Upvote 0
so you will get info about only sdcard


Code:
p.Shell("df", Array As String("sdcard"), sb, Null)  ' free space
 
Upvote 0
Try the following to return only size of sdcard ... EDIT: Oops, does not seem to work on all devices :-( ---> try the 2'nd function to see if an sdcard is mounted, seems to work on most device ...

Code:
' *** Returns amount of avalable space on specified device (in kb) ...
Sub GetAvailableSpace (DeviceName As String) As Long
    Dim ph as Phone
    Dim sb As StringBuilder
    sb.Initialize
    ' *** Returns: device_name: xxxK total, yyyyK used, zzzK available (block size nnnn)
    ph.Shell("df | grep " & DeviceName, Null, sb, Null)  ' *** Return free space of specified device only ...
    If (sb.ToString <> "") Then Return Regex.Split("K available", Regex.Split(",", sb.ToString)(2))(0) Else Return -1
End Sub

Code:
' *** Returns true if the specified device is mounted, false if not ...
Sub GetDeviceAvailable (DeviceName As String) As Boolean
    Dim sb As StringBuilder
    sb.Initialize
    ph.Shell("mount", Null, sb, Null)
    Return (sb.ToString.IndexOf(DeviceName) > -1)
End Sub
 
Last edited:
Upvote 0
Back
Top