Public Sub GetFolderFreeSpace(Folder As String) As Long
Dim jo As JavaObject
jo.InitializeNewInstance("java.io.File", Array(Folder))
Return jo.RunMethod("getUsableSpace", Null)
End Sub
Log(GetFolderFreeSpace(xui.DefaultFolder)) 'displays: 20,999 MB for mine
B4X:
Public Sub GetFolderFreeSpace(Folder As String) As String
Dim jo As JavaObject
jo.InitializeNewInstance("java.io.File", Array(Folder))
Return $"${NumberFormat(jo.RunMethod("getUsableSpace", Null)/1024/1024,1,0)} MB"$
End Sub
I did that (used NumberFormat2) but outside of the function, in the test project; I think it is more "correct" (you can use the function to do calculations)
B4X:
Public Sub GetFolderTotaleSpace(Folder As String) As Long
Dim jo As JavaObject
jo.InitializeNewInstance("java.io.File", Array(Folder))
Return jo.RunMethod("getTotalSpace", Null)
End Sub
B4X:
Public Sub GetFolderFreeSpace(Folder As String) As Long
Dim jo As JavaObject
jo.InitializeNewInstance("java.io.File", Array(Folder))
Return jo.RunMethod("getUsableSpace", Null)
End Sub
B4X:
Public Sub GetFolderFreeSpacePercent(Folder As String) As Long
' REQUIRES:
' GetFolderTotaleSpace
' GetFolderFreeSpace
Dim TotalSpace As Long = GetFolderTotaleSpace(Folder)
Return (100 - ((TotalSpace - GetFolderFreeSpace(Folder) ) / TotalSpace) * 100)
End Sub
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.