List of files in assets folder and its subfolders

try this it will work in your case

f = getAssets().list("");
for(String f1 : f){
    Log.v("names",f1);
}

The above snippet will show the contents of the asset root.

For example... if below is the asset structure..

assets
 |__Dir1
 |__Dir2
 |__File1

Snippet's output will be .... Dir1 Dir2 File1

If you need the contents of the Directory Dir1

Pass the name of Directory in the list function.

  f = getAssets().list("Dir1");

private boolean listAssetFiles(String path) {

    String [] list;
    try {
        list = getAssets().list(path);
        if (list.length > 0) {
            // This is a folder
            for (String file : list) {
                if (!listAssetFiles(path + "/" + file))
                    return false;
                else {
                    // This is a file
                    // TODO: add file name to an array list
                }
            }
        } 
    } catch (IOException e) {
        return false;
    }

    return true; 
} 

Call the listAssetFiles with the root folder name of your asset folder.

    listAssetFiles("root_folder_name_in_assets");

If the root folder is the asset folder then call it with

    listAssetFiles("");    

Tags:

Android

Assets