Thomas Smythe
Thomas Smythe

Reputation: 11

How to list folders in raw resources

I have a huge directory of infrared remote control codes, and I'd like to parse through each of them when needed. However, I am having issues trying to access the folders I have in my application's res/raw/ folder. I'd like to be able to get the folder names, because that would essentially sort for me and list out all the brands that I'd like to list in a Spinner, and then pull files from inside that folder later.

What's wrong with me doing something like this?

String path = "android.resource://" + getPackageName() + "/res/raw/";
File f = new File(path);
File[] files = f.listFiles();
for(File inFile : files){
    if(inFile.isDirectory()){
        Log.d(TAG, inFile.getName());
    }
}

Just found out that I can't create subdirectories in my res/raw folder, and I'd have to go about this through the assets folder. Would this be as simple as this structure?

assets
    - remotes
        - Samsung
            - remote1.txt
            - remote2.txt
        - Sony
            - remote1.txt
        - etc

Upvotes: 1

Views: 872

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006744

However, I am having issues trying to access the folders I have in my application's res/raw/ folder.

You cannot have folders inside of res/raw/. A resource directory can contain files, not subdirectories.

If you want to package a directory tree with your app, use assets/ and AssetManager, not raw resources.

Upvotes: 1

Related Questions