Android Question [Resolved] Include all files in a subfolder of DirAssets

Joacim

Member
Licensed User
Longtime User
Hi,

I have created a subfolder to the Files folder which I named Levels in which I store a bunch of files that describe the layout of each level in a game. I was wondering how I can make sure these files are included in the APK during compilation or do I have to put all of these files directly in the Files folder and add them that way?
 

DonManfred

Expert
Licensed User
Longtime User
AFAIK DirAssets actually cannot be used with subdirs. Put all files in DirAssets and write a sub to write the needed files to external storage into subfolders
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
I use subdirs in DirAssets with no problem simply creating this subdir in "Files". The compiler includes them normally in the apk

For instance, to reference a file under /texture subdir :

Dim DEFAULT_TEXTURE_DIR As String = File.Combine(File.DirAssets,"/texture")

And load them normaly from this dir
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I use subdirs in DirAssets with no problem simply creating this subdir in "Files". The compiler includes them normally in the apk
For instance, to reference a file under /texture subdir :
Dim DEFAULT_TEXTURE_DIR As String = File.Combine(File.DirAssets,"/texture")
And load them normaly from this dir

Ahh, ok. I did not know that. Thank you for bringing light into this
 
Upvote 0

Joacim

Member
Licensed User
Longtime User
When I try this I get a java.io.FileNotFoundException. My subfolder and files doesn't automatically get included in the APK.
 
Upvote 0

Joacim

Member
Licensed User
Longtime User
I looked inside the APK and the folder and files are indeed included. However I still get the FileNotFoundException using this code:
B4X:
LEVEL_DIR = File.Combine(File.DirAssets, "/Levels")
'...
lst = File.ReadList(LEVEL_DIR, "6.lvl")
Setting the read-only attribute on the files doesn't make any difference.
 
Upvote 0

Joacim

Member
Licensed User
Longtime User
I changed the folder name so it's in lower-case, still get the same exception. Can't the file name be just a number with a file extension, like 1.lvl, 2.lvl and so on? (I can't see why not).
 
Upvote 0

Joacim

Member
Licensed User
Longtime User
This is the exact error message I get:

An error has occurred in sub:
java.io.FileNotFoundException: /AssetsDir/levels/6.lvl: open failed:
ENOENT (No such file or directory)
 
Upvote 0

Joacim

Member
Licensed User
Longtime User
But the file clearly exists in the APK as can be seen in the attached screen shot.
 

Attachments

  • APKContent.png
    APKContent.png
    43.5 KB · Views: 230
Upvote 0

Joacim

Member
Licensed User
Longtime User
I just noticed that this line:
B4X:
LEVEL_DIR = File.Combine(File.DirAssets, "/levels")
Returns the string: /AssetsDir/levels
but the assets directory in the APK is simply named "assets" and not AssetsDir.
 
Upvote 0

Joacim

Member
Licensed User
Longtime User
OK, changing the code to this (without using the LEVEL_DIR variable) works!
B4X:
lst = File.ReadList(File.DirAssets, "levels/6.lvl")
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
From the help file.

File.Combine
Method
Returns the full path to the given file.
This methods does not support files in the assets folder.
Combine(Dir As String, FileName As String)


File.Combine combines a Diectory with a FileName not a Dir and Subdir.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Several possibilities :
- Type File.Combine in the search box just below the B4A logo and you'll get the help on top of the result screen.
- In the Documentation screen of the forum look in the Libries for Files. http://www.b4x.com/android/help/files.html#file_combine
- Download the Help documentation - B4a Object Browser from Vader.
- Or download the B4A XML file help viewer from agraham.

Both help viewers allow you to display the help files for all libraies.

agrahams help viewer runs almost all time on my computer.
 
Upvote 0

Joacim

Member
Licensed User
Longtime User
File.Combine combines a Diectory with a FileName not a Dir and Subdir.
That doesn't seem to be totally correct. That might be the intention with the method but File.Combine just seems to combine two strings and separate them with a forward slash, it doesn't check if the result is a valid path or not.

For example this: File.Combine("a","b") results in the string "a/b".
 
Upvote 0
Top