Monday 27 May 2013

How to read a folder structure in the assets folder in Android?

    AssetManager mngr_spinner = getAssets();
 try {
           int img_count = 0;
           folder_array = mngr_spinner.list(parent_folder_name);
    labels_array = new String[folder_array.length];
           for (int i = 0; i < folder_array.length; i++) 
        {
    // System.out.println("Folder " + folder_array[i]);
    if ((folder_array[i].endsWith(".png") || folder_array[i].endsWith(".jpg"))) 
         {
           img_count++;
         }
        }
      } catch (IOException e1) 
                  {
     e1.printStackTrace();
    }
Note : The folder will not be read if it has no contents in it.

No comments:

Post a Comment