Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List assets in a subdirectory using AssetManager.list

Tags:

java

android

My application has an assets directory in which I've dumped a bunch of text files I need to load at runtime.

I have a directory full of assets of a particular type (i.e., "assets/subdir") and I want to load all of the files in this directory, one at a time.

I have code like this:

 AssetManager assetMgr = getAssets();  String[] assetsIWant = assetMgr.list("subdir");  for(String asset: assetsIWant) {   doAssetyThing(asset); } 

I've tried a zillion different versions of the parameter to assetMgr.list() and am not getting anywhere.

If I use "/", I get back a list containing the "assets" directory, and a few random other items (META_INF, for example). If I pass any other string (like "assets" or "assets/" or "/assets" or "/assets/" or "mysubdir" or "/mysubdir" or "assets/mysubdir" or ...) then I get back an empty array.

The documentation is unfortunately fairly incoherent.

Does anybody know what the correct formula for that list() parameter is?

like image 233
Andrew Shelansky Avatar asked Sep 02 '10 21:09

Andrew Shelansky


1 Answers

Passing an empty string seems to work for me. I get a list of the files in my assets directory when I do the following:

AssetManager aMan = appContext.getAssets(); String[] filelist = aMan.list(""); 
like image 141
ddlw42 Avatar answered Sep 29 '22 21:09

ddlw42