amorosik Expert Licensed User Longtime User Aug 26, 2021 #1 To have the directory where to write the logs that the app produces, I use the following instructions: Dim rp As RuntimePermissions log_dir = rp.GetSafeDirDefaultExternal ("App1") How to read how much space is still available on the drive where the log_dir resides?
To have the directory where to write the logs that the app produces, I use the following instructions: Dim rp As RuntimePermissions log_dir = rp.GetSafeDirDefaultExternal ("App1") How to read how much space is still available on the drive where the log_dir resides?
M MikeSW17 Active Member Licensed User Longtime User Aug 26, 2021 #2 See: Delete oldest files, if no free space. Upvote 0
amorosik Expert Licensed User Longtime User Aug 26, 2021 #3 MikeSW17 said: See: Delete oldest files, if no free space. Click to expand... Get_FreeSpacePercent returns free space for File.DirInternal But for GetSafeDirDefaultExternal ??? Upvote 0
MikeSW17 said: See: Delete oldest files, if no free space. Click to expand... Get_FreeSpacePercent returns free space for File.DirInternal But for GetSafeDirDefaultExternal ???
agraham Expert Licensed User Longtime User Aug 26, 2021 #4 Should be the same way. Try B4X: Copy jo.InitializeNewInstance("java.io.File", Array( rp.GetSafeDirDefaultExternal )) Where 'rp' is a RuntimePermissions. Upvote 0
Should be the same way. Try B4X: Copy jo.InitializeNewInstance("java.io.File", Array( rp.GetSafeDirDefaultExternal )) Where 'rp' is a RuntimePermissions.
LucaMs Expert Licensed User Longtime User Aug 26, 2021 #5 More "general". B4X: Copy 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 Upvote 0
More "general". B4X: Copy 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
M Mahares Expert Licensed User Longtime User Aug 26, 2021 #6 LucaMs said: More "general". Click to expand... Mario, perhaps easier on the eye like this: Code: Copy Log(GetFolderFreeSpace(xui.DefaultFolder)) 'displays: 20,999 MB for mine Code: Copy 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 Upvote 0
LucaMs said: More "general". Click to expand... Mario, perhaps easier on the eye like this: Code: Copy Log(GetFolderFreeSpace(xui.DefaultFolder)) 'displays: 20,999 MB for mine Code: Copy 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
LucaMs Expert Licensed User Longtime User Aug 26, 2021 #7 Mahares said: Mario, perhaps easier on the eye like this: Click to expand... 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: Copy 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: Copy 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: Copy 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 Last edited: Aug 26, 2021 Upvote 0
Mahares said: Mario, perhaps easier on the eye like this: Click to expand... 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: Copy 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: Copy 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: Copy 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