Android Question File.ListFiles(File.Assets) in Debug

lip

Active Member
Licensed User
Longtime User
I'm using the DirAssets folder to store text files which are used in my App.

If I look in the files explorer there are 21 of these files. If I look in the files tab of the B4A IDE there are also 21 files. I have synchronised the Files tab, and used clean files and clean project.

B4X:
    'Get files from Tablet
    Dim AssetFiles As List
        AssetFiles = File.ListFiles(File.DirAssets)
    Log(AssetFiles.Size & " Asset Files Found")

If I compile in release mode there are 21 files found by ListFiles. However, if compile in debug there are 32 files. The additional files are ones that I have previously used, but removed. I may have removed them using the IDE, or deleted them from the folder, then resynced the IDE. Either way, they are completely invisible in every sense, apart from in ListFiles when compiled in Debug mode.

This is causing some grief as my App synchronises these files to a physical device when it runs, so if I try to use Debug mode it syncs the wrong files.

Can I do something to stop this?
 

DonManfred

Expert
Licensed User
Longtime User
You can not use ListFiles on the Files Folder.
 
Upvote 1

lip

Active Member
Licensed User
Longtime User
Is there a preferred solution for having a list of files that the App can access? I used to create and use a folder in the tablet's default root directory, but this got complicated with permissions.
 
Upvote 0

lip

Active Member
Licensed User
Longtime User
Thanks. This gives me DirInternal which is I guess another place to have the files. But how do I distribute the files with the App? I guess I could hard-code all the filenames and copy them from DirAssets to DirInternal when starting the App, but this defeats the object of having a fluid set of files in the assets folder and using them as required.
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
I used to create and use a folder in the tablet's default root directory ...

How did the files get into that directory? Where did they come from? And how did you know the filenames if they were "fluid"? I'm afraid that I have lost track of what you are needing to do. I don't really understand why you cannot still use DirAssets. Maybe someone else can help.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I don't really understand why you cannot still use DirAssets
This works, unless I am lost also:
B4X:
For Each f As String In File.ListFiles(File.DirAssets)
        If f.ToLowerCase.EndsWith("csv") Then  'or whatever extension
            Log(f)    'displays all csv files 
        End If
    Next
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
I'm using the DirAssets folder to store text files which are used in my App.

If I look in the files explorer there are 21 of these files. If I look in the files tab of the B4A IDE there are also 21 files. I have synchronised the Files tab, and used clean files and clean project.

B4X:
    'Get files from Tablet
    Dim AssetFiles As List
        AssetFiles = File.ListFiles(File.DirAssets)
    Log(AssetFiles.Size & " Asset Files Found")

If I compile in release mode there are 21 files found by ListFiles. However, if compile in debug there are 32 files. The additional files are ones that I have previously used, but removed. I may have removed them using the IDE, or deleted them from the folder, then resynced the IDE. Either way, they are completely invisible in every sense, apart from in ListFiles when compiled in Debug mode.

This is causing some grief as my App synchronises these files to a physical device when it runs, so if I try to use Debug mode it syncs the wrong files.

Can I do something to stop this?
Due to unintended consequences I've experienced in past projects over the years, I never rely on dynamicly-generated lists of things.

I would suggest you create a text document and store the list of files you need to use in that text document. Then your app can open the (known) text document, and use its contents as your file list (prepending the necessary file path) to work with. If you need to add/remove files then you can edit the text document and recompile.
 
Upvote 0

lip

Active Member
Licensed User
Longtime User
I am
This works, unless I am lost also:
B4X:
For Each f As String In File.ListFiles(File.DirAssets)
        If f.ToLowerCase.EndsWith("csv") Then  'or whatever extension
            Log(f)    'displays all csv files
        End If
    Next
This works in release, but not in Debug. It almost works in Debug but somehow includes files in the list that have been deleted from DirAssets a long time ago. I am getting files into the assets folder by either (i) adding them in the IDE Files tab, or (ii) adding them to the Files folder in the project and synchronising the Files tab in the IDE
 
Upvote 0

lip

Active Member
Licensed User
Longtime User
How did the files get into that directory? Where did they come from? And how did you know the filenames if they were "fluid"? I'm afraid that I have lost track of what you are needing to do. I don't really understand why you cannot still use DirAssets. Maybe someone else can help.
I am getting files into the assets folder by either (i) adding them in the IDE Files tab, or (ii) adding them to the Files folder in the project and synchronising the Files tab in the IDE. They are only 'fluid' between releases. They are actually embedded firmware files that we transfer into various electronic devices via an RF dongle. Each release of the App typically has a couple of new Firmware files and removes some old ones. The master firmware files sit in a directory on my network. I'm thinking I might drop this idea and either synchronise a Dropbox folder with a folder on the tablet, or put the firmware into a SQL column and sync it with the Apps SQLite database.
 
Upvote 0

lip

Active Member
Licensed User
Longtime User
Due to unintended consequences I've experienced in past projects over the years, I never rely on dynamicly-generated lists of things.

I would suggest you create a text document and store the list of files you need to use in that text document. Then your app can open the (known) text document, and use its contents as your file list (prepending the necessary file path) to work with. If you need to add/remove files then you can edit the text document and recompile.
I've also had the problem of capitalisation of file names getting confused when adding files, despite clicking Sync.

Thanks for the help. I think due to the various 'unintended consequences' of DirAssets I'm going to only use it for static image files from now on. I think I was trying to use it beyond its intended purpose.
 
Upvote 0
Top