Android Question Subfolders in Asset Directory

kohle

Active Member
Licensed User
Longtime User
Hi, I need subfolders in the asset directory. File.exists dont recognize the folder.
ex.
If File.Exists(File.DirAssets & "/dist","index.html") Then


What can I do without putting all files in the FILES directory ?


rgs
J.
 

DonManfred

Expert
Licensed User
Longtime User
Subfolders are not officially supported in DirAssets.

It works though.
Create a textfile about the files and the folders.
Use this file then to know what is there.
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
File.Exist does not work with File.DirAssets because you are the only person that can add files in there during the development of an app, so it's supposed that you know exactly which files are in there and which are not.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Use File.DirInternal

B4X:
Dim DirCss As String = File.Combine(File.DirInternal, "dist")
If File.Exists(DirCss, "") = False Then
    LogColor("Make Directory", xui.Color_Red)
    File.MakeDir(File.DirInternal, "dist")
End If
If File.Exists(DirCss, "style.css") = False Then
    LogColor("Create styles.css", xui.Color_Red)
    Dim styles As String = $"p {
  color: blue;
}"$
    File.WriteString(DirCss, "style.css", styles)
End If
LogColor("Reading file from " & File.Combine(DirCss, "style.css"), xui.Color_Blue) 'Reading file from /data/user/0/b4a.example/files/dist/style.css
Log(File.ReadString(DirCss, "style.css"))
 
Upvote 0
Top