title: android list all folders that has an image
body: <p>As part of my app i need to have file browser that lists only specific folders.
  For eg list only those folders in the path that an image file in any of its subfolders in any level.</p>
  
  <p>I could do it using recursion. But it affects performance. Especially finding folders at top level need many recursive calls. Is there a better way to do it </p>
  
  <p>Please see my code below</p>
  
  <pre><code>public List&lt;GeneralFileItem&gt; getGridItemsList(String root) {
      List&lt;GeneralFileItem&gt; gridItemsList = new ArrayList&lt;GeneralFileItem&gt;();
      File file;
      file = new File(root);
      File list[] = file.listFiles();
      if (list.length == 0) {
          return null;
      }
      for (int i = 0; i &lt; list.length; i++) {
          GeneralFileItem item = new GeneralFileItem();
          File temp_file = new File(file.getAbsolutePath(), list[i].getName());
          if (hasPhoto(temp_file)) {
              item.setPath(file.getAbsolutePath() + "/" + list[i].getName());
              item.setName(list[i].getName());
              if (temp_file.listFiles() != null) {
                  item.setType(GeneralFileItem.DIRECTORY_TYPE);
              } else {
                  item.setType(GeneralFileItem.FILE_TYPE);
              }
              gridItemsList.add(item);
              //Log.i(TAG,"added"+list[i].getName());
          }
      }
      return gridItemsList;
  
  }
  
  private boolean hasPhoto(File temp_file) {
      //Log.i(TAG,temp_file.getName());
  
      if (temp_file.listFiles() == null) {
          if (temp_file.getName().toUpperCase().endsWith(("JPG"))) {
              //Log.i(TAG,temp_file.getName()+ "is a photo");
              return true;
          } else
              return false;
  
      }
      else{
          File list[] = temp_file.listFiles();
  
          for (int i = 0; i &lt; list.length; i++) {
              if(hasPhoto(list[i]))
                  return true;
          }
  
      }
  
      return false;
  }
  </code></pre>
  
  <p>I want to know if there is any other way than recursive search. How are the files maintained in Android.  I know that various file systems are supported and it varies from hardware manufaturer . I would like to know if there is a way like if there is FileTable from which i can get all .jpg files .</p>