B4J Code Snippet listing File.DirAssets

Normally if you try and do
B4X:
Log(File.ListFiles(File.DirAssets))

you get message cant list DirAssets

B4X:
Dim currentFilesFolder = File.DirApp.Replace("Objects","Files")
Log(File.ListFiles(currentFilesFolder))

Seems to work fine (also for saving to the directory too in debug)

Probably a good reason not to do it though.
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
A solution that will work in all modes:

1. Add to Main or B4XMainPage:
B4X:
#CustomBuildAction: folders ready, %WINDIR%\System32\cmd.exe, /c dir /b ..\Files\ > ..\Files\dir.txt

It will create a file named dir.txt in the Files folder, during compilation, with the list of files.

2. Click on the Sync button in the Files tab to add this file. Only required once.

3. To get the files at runtime:
B4X:
For Each f As String In File.ReadList(File.DirAssets, "dir.txt")
    Log(f)
Next
 

Daestrum

Expert
Licensed User
Longtime User
Unfortunately I need a live list of files in assets while using pybridge so I can hot swap python code without restarting compile/run each time.
 
Top