5

I'm trying to get the names of my folders in "assets". I can get the names of the files with an AssetManager by using the method assetManager.list(). But the problem is that it return only files' name and not folders' names. So I'm trying to use the listFiles() method but i can't access to the Assets directory; I've try the following :

File dir = new File ("file:///android_asset/");
File[] files= dir.listFiles();

But it doesn't work :( ... Is there a way to get the folders' names contained in the Assets directory ?

Nox
  • 51
  • 2

1 Answers1

2

The URL "file:///android_asset/" doesn't point to a particular directory, it is only used by WebView to address assets. Assets are read-only and defined at compile time, so it's assumed their directory structure is known to the programmer. It's inconvenient, but that's the way it's designed

ognian
  • 11,451
  • 4
  • 35
  • 33
  • Argh ! No you're serious ? Is there really no way to do this ? (I've try also Java reflection but it only works for Raw folder not for Asset). Even if it's complex... ? – Nox Jul 19 '10 at 13:22
  • I would suggest to make a script that generates in compile time a XML or other structure representing the content of the assets directory. Why do you need to do in runtime? – ognian Jul 19 '10 at 13:41
  • Well, my app display images from asset directory but they are in a hierarchy of folders in asset. I think I'll indicate the hierarchy in the name then. With name like "flowers/roses.jpg" instead of a folder "flowers" and then manipulate the name to find the hierarchy. – Nox Jul 19 '10 at 14:00