List of assets

Hello there!

Me again with a question I’m nearly to shy to ask… ^^

So… How do I get a list of all files in a subdir of my assets folder?

I’ve got a “SoundsMusic” folder in my assets and in there are (what a surprise)

music files (*.ogg) that I want to load. For that reason I want to get a List of all

files in that dir but with

[java]

File folder = new File(“c:/”);

File[] listOfFiles = folder.listFiles();

[/java]

(edit: No, I didn’t use “c:” it was just an example. The path I tried was the right one to my asset folder. ^^)

it’s not working and in an older post (http://hub.jmonkeyengine.org/groups/import-assets/forum/topic/how-to-get-list-of-assets-available/)

it just sayes “[…] iterate through it […]”.

But how?

May anyone help me with this embarrassing problem please?

Thanks,



Markus

Whether is doable or not I don’t know as I’ve never tried or checked, but if it’s in the assets folder, you have put them there. Thus this list should be hardcoded imo. OTOH, if it’s, for example, music users can put in, then it’s not in assets and you’d have to use other ways since those files would be on the hard drive and not in the assets folder.

1 Like

Ok, true, I’ve put the songs in there and a user e.g. player should not be able to get any other

sounds into the *.jar.

For my short tracklist of 32 Songs it might be ok to hardcode them there but if I think of games

with a couple of 100 Songs (GTA or something with whole Radiostations etc.) it would get really

dumb work, writing every single song into the list per hand.



But ok, thanks for the reply!

I think I’ll put the Music into an external folder to iterate over it or just hardcode it in… :confused:

Using File won’t work for when your assets are in a jar file later anyway (if they will be).

You could use ZipInputStream or JarInputStream then, perhaps.

Just load it from the classpath via a stream.

Yes, using getResourceAsStream is definitely the way to go for loading resources if you know their names, it works for both files in folders and in jar files, but I don’t think there’s a way to list resources with it.

No, you have to compile a list. But you can add that to your ant script for example, just add a -post-compile target that lists the files and writes them to a file in the assets folder.

1 Like

Ah, good idea!